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

Declarative SCM checkout not running on certain branches

      I am running a Multibranch Pipeline with the Bitbucket branch source plugin (my configuration is in the screenshot below).  When creating a Pull Request in Bitbucket against the 'qa' branch the Declarative SCM Checkout stage does not do anything:

       

      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Declarative: Checkout SCM)
      [Pipeline] checkout
      [Pipeline] }
      

      When creating a Pull Request in Bitbucket against the 'uat' branch or the 'master' branch the pipeline everything checkouts out fine:

       

      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Declarative: Checkout SCM)
      [Pipeline] checkoutusing credential jenkins-bitbucket
      Cloning the remote Git repository
      Cloning with configured refspecs honoured and without tagsCloning repository https://bitbucket.org/myproject/myrepo.git
       > git init /home/jenkins/workspace/myrepo_PR-24 # timeout=10
      Fetching upstream changes from https://bitbucket.org/myproject/myrepo.git
       > git --version # timeout=10
      using GIT_ASKPASS to set credentials Jenkins credentials for bitbucket cloud
       > git fetch --no-tags --progress https://bitbucket.org/myproject/myrepo.git +refs/heads/jenkins:refs/remotes/origin/PR-24
       > git config remote.origin.url https://bitbucket.org/myproject/myrepo.git # timeout=10
      Fetching without tagsChecking out Revision dbf6c37eb9db62d794720bdddf3cfc740f0d5c0e (PR-24)
       > git config --add remote.origin.fetch +refs/heads/jenkins:refs/remotes/origin/PR-24 # timeout=10
       > git config remote.origin.url https://bitbucket.org/myproject/myrepo.git # timeout=10
      Fetching upstream changes from https://bitbucket.org/myproject/myrepo.git
      using GIT_ASKPASS to set credentials Jenkins credentials for bitbucket cloud
       > git fetch --no-tags --progress https://bitbucket.org/myproject/myrepo.git +refs/heads/jenkins:refs/remotes/origin/PR-24
       > git config core.sparsecheckout # timeout=10
       > git checkout -f dbf6c37eb9db62d794720bdddf3cfc740f0d5c0eCommit message: "Jenkinsfile for multibranch pipeline"
      First time build. Skipping changelog.
      [Pipeline] }
      

      Is there any way I can get verbose logging on the Declarative SCM Checkout stage? I have tried recreating the pipeline from scratch with no luck.  I've also reset my 'qa' branch to my 'uat' branch in case there was any branch corruption.

      I am running Jenkins on Kubernetes using the Kubernetes plugin to spin up agents where these jobs are run.

          [JENKINS-55879] Declarative SCM checkout not running on certain branches

          Mark Waite added a comment - - edited

          You might try copying the multibranch Pipeline job that you're using and then redefine the source code provider from Bitbucket Cloud or Bitbucket Server to Git. That may provide some additional diagnostics. You won't want to run with that long term, since there are additional features in the Bitbucket implementation that you will want, but it may help diagnose the issue with that branch.

          You might also try modifying the Jenkinsfile on the problem branch to skip the default checkout and then perform a git checkout with the checkout scm step. That may provide further diagnostics as well.

          You might check that the job definition is not configured to ignore the qa branch (with a wildcard exclusion of that name).

          You might check that the Jenkinsfile is not stored in the repository with unexpected case (for example, was it written from a Windows machine or a Mac with the name "jenkinsfile" instead of "Jenkinsfile").

          You might review the online help for the branch name exclusion field, just in case the values in that field need to be separated by something other than spaces or need to be expressed as a regular expression rather than a list of space separated matching strings.

          Mark Waite added a comment - - edited You might try copying the multibranch Pipeline job that you're using and then redefine the source code provider from Bitbucket Cloud or Bitbucket Server to Git. That may provide some additional diagnostics. You won't want to run with that long term, since there are additional features in the Bitbucket implementation that you will want, but it may help diagnose the issue with that branch. You might also try modifying the Jenkinsfile on the problem branch to skip the default checkout and then perform a git checkout with the checkout scm step. That may provide further diagnostics as well. You might check that the job definition is not configured to ignore the qa branch (with a wildcard exclusion of that name). You might check that the Jenkinsfile is not stored in the repository with unexpected case (for example, was it written from a Windows machine or a Mac with the name "jenkinsfile" instead of "Jenkinsfile"). You might review the online help for the branch name exclusion field, just in case the values in that field need to be separated by something other than spaces or need to be expressed as a regular expression rather than a list of space separated matching strings.

          Travis Ball added a comment -

          Hi Mark,

          Thanks for the quick reply.

          I switched the SCM provider to Git, but it looks like Pull Requests are not supported so I can't test my case that way.  Just to be safe I tried merging my branch with the Jenkinsfile to the 'qa' branch and built that through the Git provider.  It worked as expected, but this doesn't help my case.

          The job definition is not marked to skip the 'qa' branch.  I must have checked this hundreds of times

          I checked capitalization of the "Jenkinsfile" and it is fine.  Remember, this is building from a PR so the source is always the same.  It just fails when the destination branch is 'qa'.

          I don't think the branch name exclusion has anything to do with this because the PR is discovered, it just doesn't checkout to the branch during the pipeline.

          Travis Ball added a comment - Hi Mark, Thanks for the quick reply. I switched the SCM provider to Git, but it looks like Pull Requests are not supported so I can't test my case that way.  Just to be safe I tried merging my branch with the Jenkinsfile to the 'qa' branch and built that through the Git provider.  It worked as expected, but this doesn't help my case. The job definition is not marked to skip the 'qa' branch.  I must have checked this hundreds of times I checked capitalization of the "Jenkinsfile" and it is fine.  Remember, this is building from a PR so the source is always the same.  It just fails when the destination branch is 'qa'. I don't think the branch name exclusion has anything to do with this because the PR is discovered, it just doesn't checkout to the branch during the pipeline.

          Travis Ball added a comment -

          After many hours of trial and error I think I may have found a "solution"...

          My target branches 'qa', 'uat' & 'master' did not have the Jenkinsfile in them (only the source branch in the PR did).  I merged my branch in the 'qa' branch and now subsequent PRs to the 'qa' branch are now checking out fine.

          I think we can close this issue for now.  Thanks for your help.

          Travis Ball added a comment - After many hours of trial and error I think I may have found a "solution"... My target branches 'qa', 'uat' & 'master' did not have the Jenkinsfile in them (only the source branch in the PR did).  I merged my branch in the 'qa' branch and now subsequent PRs to the 'qa' branch are now checking out fine. I think we can close this issue for now.  Thanks for your help.

            markewaite Mark Waite
            tball33 Travis Ball
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: