Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48662

Provide a means for determining the result of running kubernetesDeploy.

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • kubernetes-cd-plugin
    • None
    • Jenkins 2.97 running on Ubuntu 16.04

      First: thanks for providing this plugin! I'm successfully using kubernetes-cd-plugin to deploy my application with a Jenkinsfile using a scripted pipeline. However, I'm struggling to determine whether or not the Deployment succeeded; I want to take different actions based on the success or failure of the deployment, and to get information about what happened that I can use within emails/slack notifications. There does not seem to be a way to do this, at least not one that's documented.

      Here's what the deploy looks like in my Jenkinsfile:

       

      kubernetesDeploy(
        configs: 'kube/jenkins/jenkins.yaml',
        credentialsType: 'SSH',
        dockerCredentials: [[credentialsId: 'my-credentials]],
        ssh: [
          sshCredentialsId: 'my-key',
          sshServer: 'localhost'
       ]
      

      This results in output like this...

      Successful Deployment

      Starting Kubernetes deployment
      Prepare Docker container registry secrets with name: acs-plugin--58r4nj89f4
      Created Secret: name: acs-plugin–58r4nj89f4
      ... <snip> ...
      Finished Kubernetes deployment

      Failed Deployment

      I modified the configs: path to point to a non-existent file, and this shows up:

      Starting Kubernetes deployment ERROR: No matching configuration files found for kube/jenkins/jenkins.yml ERROR: "ERROR: "No matching configuration files found for kube/jenkins/jenkins.yml java.lang.IllegalStateException: No matching configuration files found for kube/jenkins/jenkins.yml at com.microsoft.jenkins.kubernetes.command.DeploymentCommand$1.call(DeploymentCommand.java:83)
      ... <snip> ...
      ERROR: Kubernetes deployment ended with HasError

      What I'd like is to be able to do something like assign the kubernetesDeploy object to a variable and get information about it after it executes, something like this pseudo-code:

      deployment = kubernetesDeploy(
        configs: 'kube/jenkins/jenkins.yaml',
        credentialsType: 'SSH',
        dockerCredentials: [[credentialsId: 'my-credentials]],
        ssh: [
        sshCredentialsId: 'my-key',
        sshServer: 'localhost'
       ]
      if (deployment.success?) { 
        echo 'hooray' 
      } else {
        echo "oh no! Deployment failed with ${deployment.result}"
      }
      

      I also attempted to wrap this in a try catch, but it seems like the exception is being caught somewhere within the plugin code and not re-thrown (maybe here?) Anyway, while writing this bug (of course) I found a workaround, that I can use the currentBuild.result flag, which is set to FAILURE if the deploy fails, so I will use this for now:

      kubernetesDeploy(
        configs: 'kube/jenkins/jenkins.yaml',
        credentialsType: 'SSH',
        dockerCredentials: [[credentialsId: 'my-credentials]],
        ssh: [
          sshCredentialsId: 'my-key',
          sshServer: 'localhost'
        ]
      )
      if (currentBuild.result == 'FAILURE') {
        echo "oh no! Deployment of ${env.JOB_NAME} FAILED!")
      } else {
        echo "Yippee! Deployment of ${env.JOB_NAME} succeeded!")
      }
      

          [JENKINS-48662] Provide a means for determining the result of running kubernetesDeploy.

          Tony Flint created issue -
          Tony Flint made changes -
          Description Original: First: thanks for providing this plugin! I'm successfully [kubernetes-cd-plugin|https://github.com/jenkinsci/kubernetes-cd-plugin] to deploy my application with a Jenkinsfile using a scripted pipeline. However, I'm struggling to determine whether or not the Deployment succeeded; I want to take different actions based on the success or failure of the deployment, and to get information about what happened that I can use within emails/slack notifications. There does not seem to be a way to do this, at least not one that's documented.

          Here's what the deploy looks like in my Jenkinsfile:

           
          {code:java}
          kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
            sshCredentialsId: 'my-key',
            sshServer: 'localhost'
           ]
          {code}
          This results in output like this...

          *Successful Deployment***
          {code:java}
          Starting Kubernetes deployment
          Prepare Docker container registry secrets with name: acs-plugin--58r4nj89f4
          Created Secret: name: acs-plugin–58r4nj89f4
          ... <snip> ...
          Finished Kubernetes deployment{code}
          *Failed Deployment*

          I modified the configs: path to point to a non-existent file, and this shows up:

           
          {code:java}
          Starting Kubernetes deployment ERROR: No matching configuration files found for kube/jenkins/jenkins.yml ERROR: "ERROR: "No matching configuration files found for kube/jenkins/jenkins.yml java.lang.IllegalStateException: No matching configuration files found for kube/jenkins/jenkins.yml at com.microsoft.jenkins.kubernetes.command.DeploymentCommand$1.call(DeploymentCommand.java:83)
          ... <snip> ...
          ERROR: Kubernetes deployment ended with HasError{code}
          What I'd like is to be able to do something like assign the kubernetesDeploy object to a variable and get information about it after it executes, something like this pseudo-code:

           
          {code:java}
          deployment = kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
            sshCredentialsId: 'my-key',
            sshServer: 'localhost'
           ]
          if (deployment.success?) {
            echo 'hooray'
          } else {
            echo "oh no! Deployment failed with ${deployment.result}"
          }
          {code}
           

          I also attempted to wrap this in a try catch, but it seems like the exception is being caught somewhere within the plugin code and not re-thrown (maybe [here|https://github.com/jenkinsci/kubernetes-cd-plugin/blob/3f287806a56d6bfb075ad2e34741e05260fcf5df/src/main/java/com/microsoft/jenkins/kubernetes/command/DeploymentCommand.java#L121]?) Anyway, while writing this bug (of course) I found a workaround, that I can use the currentBuild.result flag, which is set to FAILURE if the deploy fails, so I will use this for now:

           
          {code:java}
          kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
              sshCredentialsId: 'my-key',
              sshServer: 'localhost'
            ]
          )
          if (currentBuild.result == 'FAILURE') {
            echo "oh no! Deployment of ${env.JOB_NAME} FAILED!")
          } else {
            echo "Yippee! Deployment of ${env.JOB_NAME} succeeded!")
          }
          {code}
          New: First: thanks for providing this plugin! I'm successfully using [kubernetes-cd-plugin|https://github.com/jenkinsci/kubernetes-cd-plugin] to deploy my application with a Jenkinsfile using a scripted pipeline. However, I'm struggling to determine whether or not the Deployment succeeded; I want to take different actions based on the success or failure of the deployment, and to get information about what happened that I can use within emails/slack notifications. There does not seem to be a way to do this, at least not one that's documented.

          Here's what the deploy looks like in my Jenkinsfile:

           
          {code:java}
          kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
            sshCredentialsId: 'my-key',
            sshServer: 'localhost'
           ]
          {code}
          This results in output like this...

          *Successful Deployment***
          {code:java}
          Starting Kubernetes deployment
          Prepare Docker container registry secrets with name: acs-plugin--58r4nj89f4
          Created Secret: name: acs-plugin–58r4nj89f4
          ... <snip> ...
          Finished Kubernetes deployment{code}
          *Failed Deployment*

          I modified the configs: path to point to a non-existent file, and this shows up:

           
          {code:java}
          Starting Kubernetes deployment ERROR: No matching configuration files found for kube/jenkins/jenkins.yml ERROR: "ERROR: "No matching configuration files found for kube/jenkins/jenkins.yml java.lang.IllegalStateException: No matching configuration files found for kube/jenkins/jenkins.yml at com.microsoft.jenkins.kubernetes.command.DeploymentCommand$1.call(DeploymentCommand.java:83)
          ... <snip> ...
          ERROR: Kubernetes deployment ended with HasError{code}
          What I'd like is to be able to do something like assign the kubernetesDeploy object to a variable and get information about it after it executes, something like this pseudo-code:

           
          {code:java}
          deployment = kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
            sshCredentialsId: 'my-key',
            sshServer: 'localhost'
           ]
          if (deployment.success?) {
            echo 'hooray'
          } else {
            echo "oh no! Deployment failed with ${deployment.result}"
          }
          {code}
           

          I also attempted to wrap this in a try catch, but it seems like the exception is being caught somewhere within the plugin code and not re-thrown (maybe [here|https://github.com/jenkinsci/kubernetes-cd-plugin/blob/3f287806a56d6bfb075ad2e34741e05260fcf5df/src/main/java/com/microsoft/jenkins/kubernetes/command/DeploymentCommand.java#L121]?) Anyway, while writing this bug (of course) I found a workaround, that I can use the currentBuild.result flag, which is set to FAILURE if the deploy fails, so I will use this for now:

           
          {code:java}
          kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
              sshCredentialsId: 'my-key',
              sshServer: 'localhost'
            ]
          )
          if (currentBuild.result == 'FAILURE') {
            echo "oh no! Deployment of ${env.JOB_NAME} FAILED!")
          } else {
            echo "Yippee! Deployment of ${env.JOB_NAME} succeeded!")
          }
          {code}
          Tony Flint made changes -
          Description Original: First: thanks for providing this plugin! I'm successfully using [kubernetes-cd-plugin|https://github.com/jenkinsci/kubernetes-cd-plugin] to deploy my application with a Jenkinsfile using a scripted pipeline. However, I'm struggling to determine whether or not the Deployment succeeded; I want to take different actions based on the success or failure of the deployment, and to get information about what happened that I can use within emails/slack notifications. There does not seem to be a way to do this, at least not one that's documented.

          Here's what the deploy looks like in my Jenkinsfile:

           
          {code:java}
          kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
            sshCredentialsId: 'my-key',
            sshServer: 'localhost'
           ]
          {code}
          This results in output like this...

          *Successful Deployment***
          {code:java}
          Starting Kubernetes deployment
          Prepare Docker container registry secrets with name: acs-plugin--58r4nj89f4
          Created Secret: name: acs-plugin–58r4nj89f4
          ... <snip> ...
          Finished Kubernetes deployment{code}
          *Failed Deployment*

          I modified the configs: path to point to a non-existent file, and this shows up:

           
          {code:java}
          Starting Kubernetes deployment ERROR: No matching configuration files found for kube/jenkins/jenkins.yml ERROR: "ERROR: "No matching configuration files found for kube/jenkins/jenkins.yml java.lang.IllegalStateException: No matching configuration files found for kube/jenkins/jenkins.yml at com.microsoft.jenkins.kubernetes.command.DeploymentCommand$1.call(DeploymentCommand.java:83)
          ... <snip> ...
          ERROR: Kubernetes deployment ended with HasError{code}
          What I'd like is to be able to do something like assign the kubernetesDeploy object to a variable and get information about it after it executes, something like this pseudo-code:

           
          {code:java}
          deployment = kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
            sshCredentialsId: 'my-key',
            sshServer: 'localhost'
           ]
          if (deployment.success?) {
            echo 'hooray'
          } else {
            echo "oh no! Deployment failed with ${deployment.result}"
          }
          {code}
           

          I also attempted to wrap this in a try catch, but it seems like the exception is being caught somewhere within the plugin code and not re-thrown (maybe [here|https://github.com/jenkinsci/kubernetes-cd-plugin/blob/3f287806a56d6bfb075ad2e34741e05260fcf5df/src/main/java/com/microsoft/jenkins/kubernetes/command/DeploymentCommand.java#L121]?) Anyway, while writing this bug (of course) I found a workaround, that I can use the currentBuild.result flag, which is set to FAILURE if the deploy fails, so I will use this for now:

           
          {code:java}
          kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
              sshCredentialsId: 'my-key',
              sshServer: 'localhost'
            ]
          )
          if (currentBuild.result == 'FAILURE') {
            echo "oh no! Deployment of ${env.JOB_NAME} FAILED!")
          } else {
            echo "Yippee! Deployment of ${env.JOB_NAME} succeeded!")
          }
          {code}
          New: First: thanks for providing this plugin! I'm successfully using [kubernetes-cd-plugin|https://github.com/jenkinsci/kubernetes-cd-plugin] to deploy my application with a Jenkinsfile using a scripted pipeline. However, I'm struggling to determine whether or not the Deployment succeeded; I want to take different actions based on the success or failure of the deployment, and to get information about what happened that I can use within emails/slack notifications. There does not seem to be a way to do this, at least not one that's documented.

          Here's what the deploy looks like in my Jenkinsfile:

           
          {code:java}
          kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
            sshCredentialsId: 'my-key',
            sshServer: 'localhost'
           ]
          {code}
          This results in output like this...

          *Successful Deployment*
          {code:java}
          Starting Kubernetes deployment
          Prepare Docker container registry secrets with name: acs-plugin--58r4nj89f4
          Created Secret: name: acs-plugin–58r4nj89f4
          ... <snip> ...
          Finished Kubernetes deployment{code}
          *Failed Deployment*

          I modified the configs: path to point to a non-existent file, and this shows up:
          {code:java}
          Starting Kubernetes deployment ERROR: No matching configuration files found for kube/jenkins/jenkins.yml ERROR: "ERROR: "No matching configuration files found for kube/jenkins/jenkins.yml java.lang.IllegalStateException: No matching configuration files found for kube/jenkins/jenkins.yml at com.microsoft.jenkins.kubernetes.command.DeploymentCommand$1.call(DeploymentCommand.java:83)
          ... <snip> ...
          ERROR: Kubernetes deployment ended with HasError{code}
          What I'd like is to be able to do something like assign the kubernetesDeploy object to a variable and get information about it after it executes, something like this pseudo-code:
          {code:java}
          deployment = kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
            sshCredentialsId: 'my-key',
            sshServer: 'localhost'
           ]
          if (deployment.success?) {
            echo 'hooray'
          } else {
            echo "oh no! Deployment failed with ${deployment.result}"
          }
          {code}
          I also attempted to wrap this in a try catch, but it seems like the exception is being caught somewhere within the plugin code and not re-thrown (maybe [here|https://github.com/jenkinsci/kubernetes-cd-plugin/blob/3f287806a56d6bfb075ad2e34741e05260fcf5df/src/main/java/com/microsoft/jenkins/kubernetes/command/DeploymentCommand.java#L121]?) Anyway, while writing this bug (of course) I found a workaround, that I can use the currentBuild.result flag, which is set to FAILURE if the deploy fails, so I will use this for now:
          {code:java}
          kubernetesDeploy(
            configs: 'kube/jenkins/jenkins.yaml',
            credentialsType: 'SSH',
            dockerCredentials: [[credentialsId: 'my-credentials]],
            ssh: [
              sshCredentialsId: 'my-key',
              sshServer: 'localhost'
            ]
          )
          if (currentBuild.result == 'FAILURE') {
            echo "oh no! Deployment of ${env.JOB_NAME} FAILED!")
          } else {
            echo "Yippee! Deployment of ${env.JOB_NAME} succeeded!")
          }
          {code}
          Pui Chee Chan made changes -
          Labels New: PendingRelease
          Pui Chee Chan made changes -
          Assignee Original: Azure DevOps [ azure_devops ] New: Menghua Xiao [ arieshout ]
          Menghua Xiao made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]
          Menghua Xiao made changes -
          Labels Original: PendingRelease

            arieshout Menghua Xiao
            tonyflint Tony Flint
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: