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

Groovy pipeline: Git command didn't checkout the last commit

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Trivial Trivial

      The problem: once, when I've run in Groovy pipeline [multibranch mode] git command to fetch the latest codebase to the slave workspace. The command:

      git([url: 'https://github.com/myorg/myrepo.git', branch: "${env.BRANCH_NAME}", credentialsId: "${env.CREDENTIALS_ID}"])
      

      Command output:

       > git init /home/jenkins/workspace/myjob_master-U53VEN73XGVKUQMHQMUNYUI3M2EMMZ6IAKD7LIC32FLG7MMBHHIQ # timeout=10
       > git --version # timeout=10
       > git fetch --tags --progress https://github.com/myorg/myrepot.git +refs/heads/*:refs/remotes/origin/*
       > git config remote.origin.url https://github.com/myorg/myrepo.git # timeout=10
       > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
       > git config remote.origin.url https://github.com/myorg/myrepo.git # timeout=10 
       > git fetch --tags --progress https://github.com/myorg/myrepo.git +refs/heads/*:refs/remotes/origin/*
       > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
       > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
       > git config core.sparsecheckout # timeout=10
       > git checkout -f 950c0037ee3d2b2803380baa5c0d7812a47dd6b9
       > git branch -a -v --no-abbrev # timeout=10
       > git checkout -b master 950c0037ee3d2b2803380baa5c0d7812a47dd6b9
      

      Although it has to checkout the latest version - it didn't. And there was no error in the build workflow. So, I've got the obsolete repo state, built to Docker image and finally got some sort of troubleshooting because the problem was not so obvious. When I connected to the troubled slave and check the git - the commit wasn't there. I just made a git pull into the workspace, rebuilt the Docker image and got the latest application version.
      I tried to reproduce the possible bug, but I couldn't. I rebuilt the pipeline at the clean workspace, later trying to roll out the commit with changes. And commit came! So, I still confused what kind of bug it was.

      So, please, help me to understand where is the problem might be. If you have to know additional details - please, write, what kind of.

      Thanks in advance.

          [JENKINS-41794] Groovy pipeline: Git command didn't checkout the last commit

          Mark Waite added a comment - - edited

          There is a surprising line in the git output where it says:

          > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10

          That might indicate that someone created a branch named "origin/master" in your repository. If so, that tends to confuse the git plugin. Most users don't need a branch named "origin/master", so if one exists, you should probably delete it.

          Other than that, I don't have suggestions to offer.

          Mark Waite added a comment - - edited There is a surprising line in the git output where it says: > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10 That might indicate that someone created a branch named "origin/master" in your repository. If so, that tends to confuse the git plugin. Most users don't need a branch named "origin/master", so if one exists, you should probably delete it. Other than that, I don't have suggestions to offer.

          Thanks for the reply, but I have 2 notes for this issue.

          1. We don't have and didn't have at all "origin/master" branch.
          2. I just compared the Git output of 2 builds - with commit delivery problem and without one. And the command sequence was the same, one by one, though results were really different.So, there is still a little confusion, why 2 equal processes provide different results.

          Mikhail Chinkov added a comment - Thanks for the reply, but I have 2 notes for this issue. 1. We don't have and didn't have at all "origin/master" branch. 2. I just compared the Git output of 2 builds - with commit delivery problem and without one. And the command sequence was the same, one by one, though results were really different.So, there is still a little confusion, why 2 equal processes provide different results.

          Mark Waite added a comment -

          Sorry the easy solution wasn't the real solution. Good luck finding the difference between those two scenarios. You might try some other isolation techniques like:

          1. Copy the problem job to another name, see if the problem remains across the copy. If it does, then that hints the problem is connected to the job definition. If it doesn't, then the problem may be connected to something in the original job, or to the state of the repository
          2. Run the problem job multiple times, see if the problem persists. I think your description suggests that you've already tried that, and it did not persist

          The goal is to find a set of repeatable steps that can be used to show the problem so that you (or someone else) could implement a test to show the failure, then implement a fix which is confirmed by passing the test.

          Mark Waite added a comment - Sorry the easy solution wasn't the real solution. Good luck finding the difference between those two scenarios. You might try some other isolation techniques like: Copy the problem job to another name, see if the problem remains across the copy. If it does, then that hints the problem is connected to the job definition. If it doesn't, then the problem may be connected to something in the original job, or to the state of the repository Run the problem job multiple times, see if the problem persists. I think your description suggests that you've already tried that, and it did not persist The goal is to find a set of repeatable steps that can be used to show the problem so that you (or someone else) could implement a test to show the failure, then implement a fix which is confirmed by passing the test.

          Probably there might be my misunderstanding about how Git works and how does it depend on current environment. Thanks for the suggestion, hopefully I'll debug this issue in the future.

          Mikhail Chinkov added a comment - Probably there might be my misunderstanding about how Git works and how does it depend on current environment. Thanks for the suggestion, hopefully I'll debug this issue in the future.

          why can you not use checkout scm?

          Stephen Connolly added a comment - why can you not use checkout scm ?

          Resolving as incomplete as answer to last question not provided after more than 1 month. Please reopen if answer is provided and answer is other than "oh it works if I use checkout scm"

          Stephen Connolly added a comment - Resolving as incomplete as answer to last question not provided after more than 1 month. Please reopen if answer is provided and answer is other than "oh it works if I use checkout scm "

          Oh it works if I use checkout scm
          Thanks very much

          Mikhail Chinkov added a comment - Oh it works if I use checkout scm Thanks very much

            Unassigned Unassigned
            cazorla19 Mikhail Chinkov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: