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

Wrong GIT_BRANCH returns from checkout step

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor

      I have a job where I am passing the following Map to the checkout step:

      [changelog:false, poll:false, scm:[$class:GitSCM, branches:[[name:develop]], extensions:[[$class:LocalBranch, localBranch:**]], userRemoteConfigs:[[url:https://github.com/DontShaveTheYak/jenkins-std-lib.git]]]]

      This should checkout the `develop` branch. And it used too. I have tests in a pipeline that used to pass and no longer do. The output of the step looks okay.

       

      [Pipeline] checkout The recommended git tool is: NONE No credentials specified > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/generic-example/testing/.git # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://github.com/DontShaveTheYak/jenkins-std-lib.git # timeout=10 Fetching upstream changes from https://github.com/DontShaveTheYak/jenkins-std-lib.git
      > git --version # timeout=10 > git --version # 'git version 2.30.2'
      > git fetch --tags --force --progress -- https://github.com/DontShaveTheYak/jenkins-std-lib.git +refs/heads/*:refs/remotes/origin/* # timeout=10
      > git rev-parse origin/develop^{commit} # timeout=10 Checking out Revision c268577b1bfc2c5f74cd2bd61a6c61996099b50f (origin/develop)
      > git config core.sparsecheckout # timeout=10
      > git checkout -f c268577b1bfc2c5f74cd2bd61a6c61996099b50f # timeout=10
      > git branch -a -v --no-abbrev # timeout=10
      > git branch -D develop # timeout=10
      > git checkout -b develop c268577b1bfc2c5f74cd2bd61a6c61996099b50f # timeout=10 Commit message: "Merge pull request #196 from DontShaveTheYak/develop"

      But the Map of values returned from the checkout step contains this:

      [GIT_BRANCH:origin/master, GIT_COMMIT:c268577b1bfc2c5f74cd2bd61a6c61996099b50f, GIT_LOCAL_BRANCH:master, GIT_PREVIOUS_COMMIT:c268577b1bfc2c5f74cd2bd61a6c61996099b50f, GIT_URL:https://github.com/DontShaveTheYak/jenkins-std-lib.git]

      When I verify manually with the `git branch` using `sh` I get this:

      [Pipeline] sh
      + git branch
      * develop 

      So `checkout` says were are on `master` but `git` says `develop`. To be fair they do have the same commit at the HEAD. But this used to work correctly and now doesn't.

      If someone is going to look into this I can help dig in deeper and might be able to isolate when this stopped working. 

      Possibly related to https://issues.jenkins.io/browse/JENKINS-45489 ? As this does come after a previous checkout. I first checkout my default branch and then later checkout develop.

            Unassigned Unassigned
            shadycuz Levi Blaney
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: