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

Multibranch pipelines should always show changes

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Labels:
      None
    • Environment:
      Jenkins 2.60.3
      Pipeline Plugin 2.5
      Pipeline: Multibranch 2.16
      Git Plugin 3.5.1
    • Similar Issues:

      Description

      Given a Jenkinsfile of the form:

      node {
          sh "ls"
      }
      

      If I configure a multibranch pipeline pointing to a git repo with this Jenkinsfile, Jenkins does not show changes. I have to explicitly add a checkout step:

      node {
          checkout scm
          sh "ls"
      }
      

      If Jenkins cannot find changes, it cannot notify the committers that a build has failed. For example, CulpritsRecipientProvider in the email-ext ultimately calls WorkflowRun::getChangeSets. This returns an empty list, so Jenkins doesn't know who to email.

      Adding 'checkout scm' seems redundant, because Jenkins has found the Jenkinsfile from git already. In principle, Jenkins has the data it needs to work out the changes, as far as I can see.

        Attachments

          Issue Links

            Activity

            Hide
            wilfredh Wilfred Hughes added a comment - - edited

            I encountered this today when testing the StashNotifier plugin with this minimal Jenkinsfile:

            node {
                currentBuild.result = 'SUCCESS'
                step([$class: 'StashNotifier'])
            }
            

            This is tricky because when you have a pipeline library installed, you still get notifications to the current commit of the library, but not the current project. I solved this with:

            node {
                stage("Checkout") {
                    checkout scm
                }
                currentBuild.result = 'SUCCESS'
                step([$class: 'StashNotifier'])
            }
            
            Show
            wilfredh Wilfred Hughes added a comment - - edited I encountered this today when testing the StashNotifier plugin with this minimal Jenkinsfile: node { currentBuild.result = 'SUCCESS' step([$class: 'StashNotifier' ]) } This is tricky because when you have a pipeline library installed, you still get notifications to the current commit of the library, but not the current project. I solved this with: node { stage( "Checkout" ) { checkout scm } currentBuild.result = 'SUCCESS' step([$class: 'StashNotifier' ]) }
            Hide
            wilfredh Wilfred Hughes added a comment -

            This has an interesting interaction with the stash notification plugin. Since we want to notify Stash/Bitbucket server as soon as the build has started, it's tempting to put the notification at the beginning:

            node {
                step([$class: 'StashNotifier'])
            
                stage("Checkout") {
                    checkout scm
                }
            
                try {
                    stage("Run tests") {
                        sh "bash tests.sh"
                    }
                    
                    // Set the current result, so we can send stash notifications.
                    currentBuild.result = 'SUCCESS'
                } catch (e) {
                    currentBuild.result = 'FAILURE'
                    throw e
                } finally {
                    // Notify that build completed.
                    step([$class: 'StashNotifier'])
                }
            }
            

            However, this doesn't work, because the plugin doesn't know the commit of the project under test. The correct version looks like this:

            node {
                stage("Checkout") {
                    checkout scm
                }
            
                step([$class: 'StashNotifier'])
            
                try {
                    stage("Run tests") {
                        sh "bash tests.sh"
                    }
                    
                    // Set the current result, so we can send stash notifications.
                    currentBuild.result = 'SUCCESS'
                } catch (e) {
                    currentBuild.result = 'FAILURE'
                    throw e
                } finally {
                    // Notify that build completed.
                    step([$class: 'StashNotifier'])
                }
            }
            
            Show
            wilfredh Wilfred Hughes added a comment - This has an interesting interaction with the stash notification plugin. Since we want to notify Stash/Bitbucket server as soon as the build has started, it's tempting to put the notification at the beginning: node { step([$class: 'StashNotifier' ]) stage( "Checkout" ) { checkout scm } try { stage( "Run tests" ) { sh "bash tests.sh" } // Set the current result, so we can send stash notifications. currentBuild.result = 'SUCCESS' } catch (e) { currentBuild.result = 'FAILURE' throw e } finally { // Notify that build completed. step([$class: 'StashNotifier' ]) } } However, this doesn't work, because the plugin doesn't know the commit of the project under test. The correct version looks like this: node { stage( "Checkout" ) { checkout scm } step([$class: 'StashNotifier' ]) try { stage( "Run tests" ) { sh "bash tests.sh" } // Set the current result, so we can send stash notifications. currentBuild.result = 'SUCCESS' } catch (e) { currentBuild.result = 'FAILURE' throw e } finally { // Notify that build completed. step([$class: 'StashNotifier' ]) } }
            Hide
            psionomikron Psion Omikron added a comment - - edited

            I believe we're experiencing this problem. We have a multibranch project that is not reporting any changes or git hashes except for the shared library.

            How we got here: We ran out of disk space because of the git repository replicating on each branch, so we switched to a custom checkout approach where we use worktrees, as suggested in the comments on JENKINS-32246. Because of this we're not using checkout scm.

            Show
            psionomikron Psion Omikron added a comment - - edited I believe we're experiencing this problem. We have a multibranch project that is not reporting any changes or git hashes except for the shared library. How we got here: We ran out of disk space because of the git repository replicating on each branch, so we switched to a custom checkout approach where we use worktrees, as suggested in the comments on JENKINS-32246 . Because of this we're not using checkout scm.
            Hide
            ifernandezcalvo Ivan Fernandez Calvo added a comment -

            We are seeing this issue in our PRs on the creation event any of the PRs has changes, we tried the following pipelines and none works, we used a Shared pipeline library configured globaly (I dunno if it matters), we use Jenkins 2.153,
            Pipeline 2.2, Declarative pipeline 1.33, Pipeline: Multibranch 2.20,
            Pipeline: SCM Step 2.7, SCM API Plugin 2.3.0, Github API 1.95, Basic Branch Build Strategies Plugin 1.1.1, Branch API Plugin 2.1.1,
            GitHub Branch Source Plugin 2.4.1

            regular checkout does not compute changes

            pipeline {
              agent any
              options {
                timeout(time: 1, unit: 'HOURS')
                buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
                timestamps()
                ansiColor('xterm')
                disableResume()
                durabilityHint('PERFORMANCE_OPTIMIZED')
              }
              stages {
                stage('Dummy'){
                  steps {
                    sh 'export'
                    checkout scm
                    error "Please do not continue"
                  }
                }
              }
            }
            

            using a reference repo checkout does not compute changes

            pipeline {
              agent any
              options {
                timeout(time: 1, unit: 'HOURS')
                buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
                timestamps()
                ansiColor('xterm')
                disableResume()
                durabilityHint('PERFORMANCE_OPTIMIZED')
              }
              stages {
                stage('Dummy'){
                  steps {
                    checkout([$class: 'GitSCM', 
                    branches: [[name: "${env?.CHANGE_ID ? env?.GIT_COMMIT : env?.BRANCH_NAME}"]], 
                    doGenerateSubmoduleConfigurations: false, 
                    extensions: [[$class: 'CloneOption', 
                      noTags: false, 
                      reference: '/var/lib/jenkins/.git-references/apm-agent-go.git', 
                      shallow: false]], 
                    submoduleCfg: [], 
                    userRemoteConfigs: [[credentialsId: 'UserAndToken', 
                    url: "${env?.GIT_URL}"]]])
                    error "Please do not continue"
                  }
                }
              }
            }
            

            using ChangelogToBranch checkout does not compute changes

            pipeline {
              agent any
              options {
                timeout(time: 1, unit: 'HOURS')
                buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
                timestamps()
                ansiColor('xterm')
                disableResume()
                durabilityHint('PERFORMANCE_OPTIMIZED')
              }
              stages {
                stage('Dummy'){
                  steps {
                    checkout([$class: 'GitSCM', 
                      branches: [[name: "${env?.CHANGE_ID ? env?.GIT_COMMIT : env?.BRANCH_NAME}"]],
                      doGenerateSubmoduleConfigurations: false, 
                      extensions: [
                        [$class: 'ChangelogToBranch', 
                          options: [compareRemote: "${env?.GIT_URL}", 
                          compareTarget: "${env?.CHANGE_ID ? env?.CHANGE_TARGET : 'master'}"]]], 
                      submoduleCfg: [], 
                      userRemoteConfigs: [
                        [credentialsId: 'UserAndToken', 
                        url: "${env?.GIT_URL}"]]])
                    error "Please do not continue"
                  }
                }
              }
            }
            
            Show
            ifernandezcalvo Ivan Fernandez Calvo added a comment - We are seeing this issue in our PRs on the creation event any of the PRs has changes, we tried the following pipelines and none works, we used a Shared pipeline library configured globaly (I dunno if it matters), we use Jenkins 2.153, Pipeline 2.2, Declarative pipeline 1.33, Pipeline: Multibranch 2.20, Pipeline: SCM Step 2.7, SCM API Plugin 2.3.0, Github API 1.95, Basic Branch Build Strategies Plugin 1.1.1, Branch API Plugin 2.1.1, GitHub Branch Source Plugin 2.4.1 regular checkout does not compute changes pipeline { agent any options { timeout(time: 1, unit: 'HOURS' ) buildDiscarder(logRotator(numToKeepStr: '20' , artifactNumToKeepStr: '20' , daysToKeepStr: '30' )) timestamps() ansiColor( 'xterm' ) disableResume() durabilityHint( 'PERFORMANCE_OPTIMIZED' ) } stages { stage( 'Dummy' ){ steps { sh 'export' checkout scm error "Please do not continue " } } } } using a reference repo checkout does not compute changes pipeline { agent any options { timeout(time: 1, unit: 'HOURS' ) buildDiscarder(logRotator(numToKeepStr: '20' , artifactNumToKeepStr: '20' , daysToKeepStr: '30' )) timestamps() ansiColor( 'xterm' ) disableResume() durabilityHint( 'PERFORMANCE_OPTIMIZED' ) } stages { stage( 'Dummy' ){ steps { checkout([$class: 'GitSCM' , branches: [[name: "${env?.CHANGE_ID ? env?.GIT_COMMIT : env?.BRANCH_NAME}" ]], doGenerateSubmoduleConfigurations: false , extensions: [[$class: 'CloneOption' , noTags: false , reference: '/ var /lib/jenkins/.git-references/apm-agent-go.git' , shallow: false ]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'UserAndToken' , url: "${env?.GIT_URL}" ]]]) error "Please do not continue " } } } } using ChangelogToBranch checkout does not compute changes pipeline { agent any options { timeout(time: 1, unit: 'HOURS' ) buildDiscarder(logRotator(numToKeepStr: '20' , artifactNumToKeepStr: '20' , daysToKeepStr: '30' )) timestamps() ansiColor( 'xterm' ) disableResume() durabilityHint( 'PERFORMANCE_OPTIMIZED' ) } stages { stage( 'Dummy' ){ steps { checkout([$class: 'GitSCM' , branches: [[name: "${env?.CHANGE_ID ? env?.GIT_COMMIT : env?.BRANCH_NAME}" ]], doGenerateSubmoduleConfigurations: false , extensions: [ [$class: 'ChangelogToBranch' , options: [compareRemote: "${env?.GIT_URL}" , compareTarget: "${env?.CHANGE_ID ? env?.CHANGE_TARGET : 'master' }" ]]], submoduleCfg: [], userRemoteConfigs: [ [credentialsId: 'UserAndToken' , url: "${env?.GIT_URL}" ]]]) error "Please do not continue " } } } }
            Show
            ifernandezcalvo Ivan Fernandez Calvo added a comment - nice input about this one https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/jenkinsci-users/Ew-7R2rToDQ/THz_c0z7BgAJ

              People

              • Assignee:
                Unassigned
                Reporter:
                wilfredh Wilfred Hughes
              • Votes:
                3 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated: