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

Checkout in second stage sets SUCCESS on Github commit

    Details

    • Similar Issues:

      Description

      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
      

        Attachments

          Issue Links

            Activity

            Hide
            vorobievalex Alexander Vorobiev added a comment -

            Works fine now. Thanks a lot!

            Show
            vorobievalex Alexander Vorobiev added a comment - Works fine now. Thanks a lot!
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Stephen Connolly
            Path:
            src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubNotificationContext.java
            http://jenkins-ci.org/commit/github-branch-source-plugin/23480ace348f5515e227e507d5aeeda46fc93c89
            Log:
            Merge pull request #175 from steven-foster/JENKINS-47366

            JENKINS-47366 Avoid reporting premature build status

            Compare: https://github.com/jenkinsci/github-branch-source-plugin/compare/c088f0b60bf9...23480ace348f
            *NOTE:* This service been marked for deprecation: https://developer.github.com/changes/2018-04-25-github-services-deprecation/

            Functionality will be removed from GitHub.com on January 31st, 2019.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Stephen Connolly Path: src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubNotificationContext.java http://jenkins-ci.org/commit/github-branch-source-plugin/23480ace348f5515e227e507d5aeeda46fc93c89 Log: Merge pull request #175 from steven-foster/ JENKINS-47366 JENKINS-47366 Avoid reporting premature build status Compare: https://github.com/jenkinsci/github-branch-source-plugin/compare/c088f0b60bf9...23480ace348f * NOTE: * This service been marked for deprecation: https://developer.github.com/changes/2018-04-25-github-services-deprecation/ Functionality will be removed from GitHub.com on January 31st, 2019.
            Show
            stevenfoster Steven Foster added a comment - I have an open PR at  https://github.com/jenkinsci/github-branch-source-plugin/pull/175
            Hide
            timja Tim Jacomb added a comment -

            Steven Foster Did you get anywhere with this?

            Show
            timja Tim Jacomb added a comment - Steven Foster Did you get anywhere with this?
            Hide
            vorobievalex Alexander Vorobiev added a comment -

            Awesome! Looking forward to be able to split our monolith stages.

            Show
            vorobievalex Alexander Vorobiev added a comment - Awesome! Looking forward to be able to split our monolith stages.

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: