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

Checkout in second stage sets SUCCESS on Github commit

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • None
    • Jenkins 2.73.1
      GitHub Branch Source Plugin 2.2.3

      In a multi-agent pipeline, 'checkout' step sets SUCCESS status to Github commit. This happens if any previous stage already published successful build result.

      So commit is marked as SUCCESS for some time. If later tests fail, commit status is changed for FAILURE. This enables bad code merge from a PR and bad code deployment.

      This is seen in several complex pipelines with the both pipeline default checkout and with checkout scm. Here is a minimal example, where junit or any other publishing step replaced with currentBuild.result = 'SUCCESS':

      pipeline {
          agent none
      
          stages {
              stage('Set SUCCESS') {
                  agent any
                  steps {
                      script {
                          currentBuild.result = 'SUCCESS'
                      }
                  }
              }
              stage('Checkout, test, fail') {
                  agent any
                  steps {
                      sh """sleep 60
                            exit 1"""
                  }
              }
          }
      }
      

      Here are selected lines rom a build log. Note two 'GitHub has been notified' messages:

      Branch indexing
      06:33:50 Connecting to https://api.github.com using ****
      Obtained Jenkinsfile from 2c5c8ce94a1ba597eab4c959a4f43f505c38a77c
      [Pipeline] stage
      [Pipeline] { (Set SUCCESS)
      [Pipeline] node
      Running on master in /Home/workspace/a_a_a-NZHSOOK6DLZNS5KEQNGRGFRRYDRS74EJJG6PZYDHEPRJUQRTRCDA
      [Pipeline] {
      [Pipeline] checkout
      ...<log cut>
      [Pipeline] withEnv
      [Pipeline] {
      [Pipeline] script
      [Pipeline] {
      [Pipeline] }
      [Pipeline] // script
      [Pipeline] }
      [Pipeline] // withEnv
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Checkout, test, fail)
      [Pipeline] node
      Running on master in /Home/workspace/a_a_a-NZHSOOK6DLZNS5KEQNGRGFRRYDRS74EJJG6PZYDHEPRJUQRTRCDA
      [Pipeline] {
      [Pipeline] checkout
       > /usr/bin/git rev-parse --is-inside-work-tree # timeout=60
      Fetching changes from the remote Git repository
      ...<log cut>
       > /usr/bin/git config core.sparsecheckout # timeout=60
       > /usr/bin/git checkout -f 7ce1f7ba4b355294f3fc475b9d84528eba3669cb
      Commit message: "Update Jenkinsfile"
      
      GitHub has been notified of this commit’s build result
      
      [Pipeline] withEnv
      [Pipeline] {
      [Pipeline] sh
      [a_a_a-NZHSOOK6DLZNS5KEQNGRGFRRYDRS74EJJG6PZYDHEPRJUQRTRCDA] Running shell script
      + sleep 60
      + exit 1
      [Pipeline] }
      [Pipeline] // withEnv
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] End of Pipeline
      
      GitHub has been notified of this commit’s build result
      
      ERROR: script returned exit code 1
      Finished: FAILURE
      

            stevenfoster Steven Foster
            vorobievalex Alexander Vorobiev
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: