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

Jenkins plugin sends SUCCESS status to Jira upon failed build in Jenkins pipeline script

    XMLWordPrintable

Details

    Description

      Build pipeline:

      #!groovy
      
      env.DOCKER_HOST_IP = '172.17.0.1'
      
      node('jenkins-build-agent') {
          // This limits build concurrency to 1 per branch
          properties([disableConcurrentBuilds()])    
          
          env.JAVA_HOME = "${tool 'jdk8'}"
          
          timeout(10 /* minutes */) {
              ws("workspace/${env.JOB_NAME}") {
                  try {
                    
          
                     stage('Checkout') {
                          git branch: getBranchName(),
                              credentialsId: 'github-token',
                              url: 'https://....git'
                      }
         
          
                      stage('Build') {
                          error("Build failed: test")
                      }
                  } finally {
                      echo "sending jiraSendBuildInfo"
                      jiraSendBuildInfo()
                      echo "finished jiraSendBuildInfo"
                  
                      cleanWs() // clean up workspace    
                  }
              }
          }
      }

      Actual result:

      When a build fails this pipeline sends SUCCESS state into related Jira issue.

       

      Expected result:

      Jenkins should send FAILED status into related Jira issue.

      Attachments

        Activity

          rafalmyslek Rafal Myslek added a comment -

          The issue is because Pipeline job depends on transitive dependency on Declarative:pipeline, which is giving currentBuild.currentResult as null. Default value inside atlassian-jira-software-cloud plugin if currentBuild.currentResult is null is "Success". Thats why success status being sent to jira for failure build. We are working on bumping the version of the dependency to make this feature work.

          rafalmyslek Rafal Myslek added a comment - The issue is because Pipeline job depends on transitive dependency on Declarative:pipeline, which is giving currentBuild.currentResult as null. Default value inside atlassian-jira-software-cloud plugin if currentBuild.currentResult is null is "Success". Thats why success status being sent to jira for failure build. We are working on bumping the version of the dependency to make this feature work.
          nsurendran Navya added a comment -

          abeletsky, As a work around you can set currentBuild.result as FAILURE inside catch block and then invoke jiraSendBuildInfo() to Jira for sending build information to jira. This will solve the issue.

          catch (Exception err) {
                   currentBuild.result = 'FAILURE'
                    echo "${currentBuild.result}, ${currentBuild.currentResult}"
                   jiraSendBuildInfo()
          }

          nsurendran Navya added a comment - abeletsky , As a work around you can set currentBuild.result as FAILURE inside catch block and then invoke jiraSendBuildInfo() to Jira for sending build information to jira. This will solve the issue. catch (Exception err) {          currentBuild.result = 'FAILURE'           echo "${currentBuild.result}, ${currentBuild.currentResult}"          jiraSendBuildInfo() }

          Thank you! I will use a workaround until the issue is fixed.

          abeletsky Andrey Beletsky added a comment - Thank you! I will use a workaround until the issue is fixed.

          People

            nsurendran Navya
            abeletsky Andrey Beletsky
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: