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

checkout scm produces bad value for GIT_COMMIT

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Jenkins 2.138.1
      cloudbees-bitbucket-branch-source 2.2.12

      When my pipelinejob-from-source starts up, Jenkins fetches the repository to read the Jenkinsfile. A merge commit is created so that the branch under test gets the latest changes from master. If master branch is ahead of the branch under test, a merge commit will be created, otherwise it's a fast-forward merge.

      Later in my Jenkinsfile I do "scmVars = checkout scm". Now basically the same thing happens again with potential merge commit etc.

      The problem: If a merge commit is needed, the second one coming from "checkout scm" produces a different hash compared to when the Jenkinsfile was fetched. However, scmVars.GIT_COMMIT equals the hash from the former leading to:

       

       
      fatal: Invalid symmetric difference expression bdd2a3f24fa8f245c5ffcf1cf2e63996a68fbea4...
      

       

      when trying to use that hash.

       

      Logs that show the scenario:

       

      # Jenkins file reading
      Checking out git https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git into /var/jenkins_home/workspace/test_my-repo_PR-7-LVZDG64ZTHYZAIGZCKKNQGUIHWPWPRPNEENFGIUG5KIOKAMV3FNA@script to read Jenkinsfile
       > git rev-parse --is-inside-work-tree # timeout=10
      Fetching changes from 2 remote Git repositories
       > git config remote.origin.url https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git # timeout=10
      Fetching upstream changes from https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git
       > git --version # timeout=10
      using GIT_ASKPASS to set credentials 
       > git fetch --tags --progress https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git +refs/pull-requests/7/from:refs/remotes/origin/PR-7
       > git config remote.upstream.url https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git # timeout=10
      Fetching upstream changes from https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git
      using GIT_ASKPASS to set credentials 
       > git fetch --tags --progress https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git +refs/heads/master:refs/remotes/upstream/master
      Merging remotes/upstream/master commit b49d50909a5f1178ac0ffad63372c49e83ad66c9 into PR head commit 21fbbaebcdfd83a77b57809befd518e836303c54
       > git config core.sparsecheckout # timeout=10
       > git checkout -f 21fbbaebcdfd83a77b57809befd518e836303c54
       > git merge b49d50909a5f1178ac0ffad63372c49e83ad66c9 # timeout=10
       > git rev-parse HEAD^{commit} # timeout=10
      Merge succeeded, producing bdd2a3f24fa8f245c5ffcf1cf2e63996a68fbea4
      ...
      #checkout part
      [Pipeline] checkout
      15:01:35 Cloning the remote Git repository
      15:01:35 Cloning repository https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git
      15:01:35 > git init /home/jenkins/workspace/test_my-repo_PR-7-LVZDG64ZTHYZAIGZCKKNQGUIHWPWPRPNEENFGIUG5KIOKAMV3FNA # timeout=10
      15:01:35 Fetching upstream changes from https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git
      15:01:35 > git --version # timeout=10
      15:01:35 using GIT_ASKPASS to set credentials 
      15:01:35 > git fetch --tags --progress https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git +refs/heads/*:refs/remotes/origin/*
      15:01:36 > git config remote.origin.url https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git # timeout=10
      15:01:36 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
      15:01:36 > git config remote.origin.url https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git # timeout=10
      15:01:36 Fetching upstream changes from https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git
      15:01:36 using GIT_ASKPASS to set credentials 
      15:01:36 > git fetch --tags --progress https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git +refs/pull-requests/7/from:refs/remotes/origin/PR-7
      15:01:36 > git config remote.upstream.url https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git # timeout=10
      15:01:36 Fetching upstream changes from https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git
      15:01:36 using GIT_ASKPASS to set credentials 
      15:01:36 > git fetch --tags --progress https://bitbucket.xyz.com/bitbucket/scm/test/my-repo.git +refs/heads/master:refs/remotes/upstream/master
      15:01:36 Merging remotes/upstream/master commit b49d50909a5f1178ac0ffad63372c49e83ad66c9 into PR head commit 21fbbaebcdfd83a77b57809befd518e836303c54
      15:01:36 > git config core.sparsecheckout # timeout=10
      15:01:36 > git checkout -f 21fbbaebcdfd83a77b57809befd518e836303c54
      15:01:36 > git merge b49d50909a5f1178ac0ffad63372c49e83ad66c9 # timeout=10
      15:01:36 > git rev-parse HEAD^{commit} # timeout=10
      15:01:36 Merge succeeded, producing 000440292a594714a1a85cf869c7ab4af11f78c7
      ...
      #trying to use scmVars.GIT_COMMIT
      git log bdd2a3f24fa8f245c5ffcf1cf2e63996a68fbea4
      15:01:39 fatal: Invalid symmetric difference expression bdd2a3f24fa8f245c5ffcf1cf2e63996a68fbea4

            Unassigned Unassigned
            henrikb Henrik Brunberg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: