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

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

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • None
    • Jenkins 2.289.3, atlassian-jira-software-cloud-plugin 1.4.4

      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.

          [JENKINS-66266] Jenkins plugin sends SUCCESS status to Jira upon failed build in Jenkins pipeline script

          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.

          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.

          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()
          }

          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.

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

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

              Created:
              Updated: