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

Provide a means for determining the result of running kubernetesDeploy.

XMLWordPrintable

    • 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!")
      }
      

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

              Created:
              Updated:
              Resolved: