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

Wrong value for GIT_COMMIT after merge?

    XMLWordPrintable

Details

    Description

      This issue is just for documentation, since the issue went away with the update to gitlab-branch-source 1.4.4. Before that, a merge request would do a "fat" instead a lightweight checkout to read the Jenkinsfile and I cannot reproduce the issue when just a lightweight checkout is done.

      Pipeline sample code to have something to talk about:

      def repo = checkout scm
      echo repo.GIT_COMMIT
      

      This works correctly for branch builds, but not for merge request builds and the strategy "Merging the merge request with the current target branch revision" - when using that strategy, GIT_COMMIT points to a revision which doesn't exist after the merge, but instead to the merge commit from the "temporary" chechout which was done for reading the Jenkinsfile. Relevant log snippets:

      Branch indexing
      Querying the current revision of merge request #3...
      Current revision of merge request #3 is 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
      Checking out git https://<REPO>.git into /var/lib/jenkins/workspace/SOMETHING_MR-3@script to read Jenkinsfile
      [...]
       > git fetch --no-tags --force --progress -- https://<REPO>.git +refs/merge-requests/3/head:refs/remotes/origin/MR-3 +refs/heads/master:refs/remotes/origin/master # timeout=10
      Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
      [...]
      Merge succeeded, producing a9473d5a2d79ace679affe37853e74950602b07b
      Checking out Revision a9473d5a2d79ace679affe37853e74950602b07b (feature/update-slf4j)
      [...]
      Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
      [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
      [GitLab Pipeline Status] Notified
      Running in Durability level: PERFORMANCE_OPTIMIZED
      [...]
      [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
      [Pipeline] Start of Pipeline
      [...]
      [Pipeline] checkout
      [...]
      Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
      [...]
      Merge succeeded, producing bdabb0071fa91fe128c037a9f3352b459fcfcde8
      Checking out Revision bdabb0071fa91fe128c037a9f3352b459fcfcde8 (feature/update-slf4j)
      [...]
      Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
      First time build. Skipping changelog.
      [...]
      [Pipeline] echo
      {GIT_AUTHOR_EMAIL=xxx, GIT_AUTHOR_NAME=xxx, GIT_BRANCH=feature/update-slf4j, GIT_COMMIT=a9473d5a2d79ace679affe37853e74950602b07b, GIT_COMMITTER_EMAIL=xxx, GIT_COMMITTER_NAME=xxx, GIT_LOCAL_BRANCH=feature/update-slf4j, GIT_PREVIOUS_COMMIT=873ac16b7ac3b44ad9b45cdde7479a3dd73a4beb, GIT_PREVIOUS_SUCCESSFUL_COMMIT=367f5bc9835cecaf5929cf9a6a8d3600ad1dae32, GIT_URL=https://<REPO>.git}
      [...]
      + git log --oneline -2
      bdabb00 Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD
      eb6a580 Update test output
      [...]
      

      Now, with a lightweight checkout:

      Started by user Tobias Gruetzmacher
      Querying the current revision of merge request #3...
      Current revision of merge request #3 is 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
      Obtained Jenkinsfile from eb6a5804b1a07157304d00562a489437342049e1+367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
      Running in Durability level: PERFORMANCE_OPTIMIZED
      [...]
      [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
      [GitLab Pipeline Status] Notified
      [Pipeline] Start of Pipeline
      [...]
      [Pipeline] checkout
      [...]
      Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
      [...]
      Merge succeeded, producing 793df539d53a54cb84316c39f81939c344255e4b
      Checking out Revision 793df539d53a54cb84316c39f81939c344255e4b (feature/update-slf4j)
      [...]
      Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
      First time build. Skipping changelog.
      [...]
      [Pipeline] echo
      {GIT_AUTHOR_EMAIL=xxx, GIT_AUTHOR_NAME=xxx, GIT_BRANCH=feature/update-slf4j, GIT_COMMIT=793df539d53a54cb84316c39f81939c344255e4b, GIT_COMMITTER_EMAIL=xxx, GIT_COMMITTER_NAME=xxx, GIT_LOCAL_BRANCH=feature/update-slf4j, GIT_PREVIOUS_COMMIT=a9473d5a2d79ace679affe37853e74950602b07b, GIT_PREVIOUS_SUCCESSFUL_COMMIT=367f5bc9835cecaf5929cf9a6a8d3600ad1dae32, GIT_URL=https://<REPO>.git}
      [...]
      + git log --oneline -2
      793df53 Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD
      eb6a580 Update test output
      [...]
      

      Attachments

        Activity

          tgr Tobias Gruetzmacher created issue -
          tgr Tobias Gruetzmacher made changes -
          Field Original Value New Value
          Description This issue is just for documentation, since the issue went away with the update to gitlab-branch-source [1.4.4](https://github.com/jenkinsci/gitlab-branch-source-plugin/releases/tag/gitlab-branch-source-1.4.4). Before that, a merge request would do a "fat" instead a lightweight checkout to read the {{Jenkinsfile}} and I cannot reproduce the issue when just a lightweight checkout is done.

          Pipeline sample code to have somethingto talk about:

          {code:java}
          def repo = checkout scm
          echo repo.GIT_COMMIT
          {code}

          This works correctly for branch builds, but not for merge request builds and the strategy "Merging the merge request with the current target branch revision" - when using that strategy, {{GIT_COMMIT}} points to a revision which doesn't exist after the merge, but instead to the merge commit from the "temporary" chechout which was done for reading the {{Jenkinsfile}}. Relevant log snippets:

          {noformat}
          Branch indexing
          Querying the current revision of merge request #3...
          Current revision of merge request #3 is 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Checking out git https://&lt;REPO&gt;.git into /var/lib/jenkins/workspace/SOMETHING_MR-3@script to read Jenkinsfile
          [...]
           > git fetch --no-tags --force --progress -- https://&lt;REPO&gt;.git +refs/merge-requests/3/head:refs/remotes/origin/MR-3 +refs/heads/master:refs/remotes/origin/master # timeout=10
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing a9473d5a2d79ace679affe37853e74950602b07b
          Checking out Revision a9473d5a2d79ace679affe37853e74950602b07b (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [GitLab Pipeline Status] Notified
          Running in Durability level: PERFORMANCE_OPTIMIZED
          [...]
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [Pipeline] Start of Pipeline
          [...]
          [Pipeline] checkout
          [...]
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing bdabb0071fa91fe128c037a9f3352b459fcfcde8
          Checking out Revision bdabb0071fa91fe128c037a9f3352b459fcfcde8 (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          First time build. Skipping changelog.
          [...]
          [Pipeline] echo
          {GIT_AUTHOR_EMAIL=someidiot@inform-software.com, GIT_AUTHOR_NAME=Test-Jenkins, GIT_BRANCH=feature/update-slf4j, GIT_COMMIT=a9473d5a2d79ace679affe37853e74950602b07b, GIT_COMMITTER_EMAIL=someidiot@inform-software.com, GIT_COMMITTER_NAME=Test-Jenkins, GIT_LOCAL_BRANCH=feature/update-slf4j, GIT_PREVIOUS_COMMIT=873ac16b7ac3b44ad9b45cdde7479a3dd73a4beb, GIT_PREVIOUS_SUCCESSFUL_COMMIT=367f5bc9835cecaf5929cf9a6a8d3600ad1dae32, GIT_URL=https://&lt;REPO&gt;.git}
          [...]
          + git log --oneline -2
          bdabb00 Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD
          eb6a580 Update test output
          [...]
          {noformat}

          Now, with a lightweight checkout:
          {noformat}
          Started by user Tobias Gruetzmacher
          Querying the current revision of merge request #3...
          Current revision of merge request #3 is 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Obtained Jenkinsfile from eb6a5804b1a07157304d00562a489437342049e1+367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Running in Durability level: PERFORMANCE_OPTIMIZED
          [...]
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [GitLab Pipeline Status] Notified
          [Pipeline] Start of Pipeline
          [...]
          [Pipeline] checkout
          [...]
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing 793df539d53a54cb84316c39f81939c344255e4b
          Checking out Revision 793df539d53a54cb84316c39f81939c344255e4b (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          First time build. Skipping changelog.
          [...]
          [Pipeline] echo
          {GIT_AUTHOR_EMAIL=someidiot@inform-software.com, GIT_AUTHOR_NAME=Test-Jenkins, GIT_BRANCH=feature/update-slf4j, GIT_COMMIT=793df539d53a54cb84316c39f81939c344255e4b, GIT_COMMITTER_EMAIL=someidiot@inform-software.com, GIT_COMMITTER_NAME=Test-Jenkins, GIT_LOCAL_BRANCH=feature/update-slf4j, GIT_PREVIOUS_COMMIT=a9473d5a2d79ace679affe37853e74950602b07b, GIT_PREVIOUS_SUCCESSFUL_COMMIT=367f5bc9835cecaf5929cf9a6a8d3600ad1dae32, GIT_URL=https://git.inform-software.com/tgruetzm/versions.git}
          [...]
          + git log --oneline -2
          793df53 Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD
          eb6a580 Update test output
          [...]
          {noformat}
          This issue is just for documentation, since the issue went away with the update to gitlab-branch-source [1.4.4|https://github.com/jenkinsci/gitlab-branch-source-plugin/releases/tag/gitlab-branch-source-1.4.4]. Before that, a merge request would do a "fat" instead a lightweight checkout to read the {{Jenkinsfile}} and I cannot reproduce the issue when just a lightweight checkout is done.

          Pipeline sample code to have something to talk about:

          {code:java}
          def repo = checkout scm
          echo repo.GIT_COMMIT
          {code}

          This works correctly for branch builds, but not for merge request builds and the strategy "Merging the merge request with the current target branch revision" - when using that strategy, {{GIT_COMMIT}} points to a revision which doesn't exist after the merge, but instead to the merge commit from the "temporary" chechout which was done for reading the {{Jenkinsfile}}. Relevant log snippets:

          {noformat}
          Branch indexing
          Querying the current revision of merge request #3...
          Current revision of merge request #3 is 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Checking out git https://&lt;REPO&gt;.git into /var/lib/jenkins/workspace/SOMETHING_MR-3@script to read Jenkinsfile
          [...]
           > git fetch --no-tags --force --progress -- https://&lt;REPO&gt;.git +refs/merge-requests/3/head:refs/remotes/origin/MR-3 +refs/heads/master:refs/remotes/origin/master # timeout=10
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing a9473d5a2d79ace679affe37853e74950602b07b
          Checking out Revision a9473d5a2d79ace679affe37853e74950602b07b (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [GitLab Pipeline Status] Notified
          Running in Durability level: PERFORMANCE_OPTIMIZED
          [...]
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [Pipeline] Start of Pipeline
          [...]
          [Pipeline] checkout
          [...]
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing bdabb0071fa91fe128c037a9f3352b459fcfcde8
          Checking out Revision bdabb0071fa91fe128c037a9f3352b459fcfcde8 (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          First time build. Skipping changelog.
          [...]
          [Pipeline] echo
          {GIT_AUTHOR_EMAIL=someidiot@inform-software.com, GIT_AUTHOR_NAME=Test-Jenkins, GIT_BRANCH=feature/update-slf4j, GIT_COMMIT=a9473d5a2d79ace679affe37853e74950602b07b, GIT_COMMITTER_EMAIL=someidiot@inform-software.com, GIT_COMMITTER_NAME=Test-Jenkins, GIT_LOCAL_BRANCH=feature/update-slf4j, GIT_PREVIOUS_COMMIT=873ac16b7ac3b44ad9b45cdde7479a3dd73a4beb, GIT_PREVIOUS_SUCCESSFUL_COMMIT=367f5bc9835cecaf5929cf9a6a8d3600ad1dae32, GIT_URL=https://&lt;REPO&gt;.git}
          [...]
          + git log --oneline -2
          bdabb00 Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD
          eb6a580 Update test output
          [...]
          {noformat}

          Now, with a lightweight checkout:
          {noformat}
          Started by user Tobias Gruetzmacher
          Querying the current revision of merge request #3...
          Current revision of merge request #3 is 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Obtained Jenkinsfile from eb6a5804b1a07157304d00562a489437342049e1+367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Running in Durability level: PERFORMANCE_OPTIMIZED
          [...]
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [GitLab Pipeline Status] Notified
          [Pipeline] Start of Pipeline
          [...]
          [Pipeline] checkout
          [...]
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing 793df539d53a54cb84316c39f81939c344255e4b
          Checking out Revision 793df539d53a54cb84316c39f81939c344255e4b (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          First time build. Skipping changelog.
          [...]
          [Pipeline] echo
          {GIT_AUTHOR_EMAIL=someidiot@inform-software.com, GIT_AUTHOR_NAME=Test-Jenkins, GIT_BRANCH=feature/update-slf4j, GIT_COMMIT=793df539d53a54cb84316c39f81939c344255e4b, GIT_COMMITTER_EMAIL=someidiot@inform-software.com, GIT_COMMITTER_NAME=Test-Jenkins, GIT_LOCAL_BRANCH=feature/update-slf4j, GIT_PREVIOUS_COMMIT=a9473d5a2d79ace679affe37853e74950602b07b, GIT_PREVIOUS_SUCCESSFUL_COMMIT=367f5bc9835cecaf5929cf9a6a8d3600ad1dae32, GIT_URL=https://git.inform-software.com/tgruetzm/versions.git}
          [...]
          + git log --oneline -2
          793df53 Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD
          eb6a580 Update test output
          [...]
          {noformat}
          tgr Tobias Gruetzmacher made changes -
          Description This issue is just for documentation, since the issue went away with the update to gitlab-branch-source [1.4.4|https://github.com/jenkinsci/gitlab-branch-source-plugin/releases/tag/gitlab-branch-source-1.4.4]. Before that, a merge request would do a "fat" instead a lightweight checkout to read the {{Jenkinsfile}} and I cannot reproduce the issue when just a lightweight checkout is done.

          Pipeline sample code to have something to talk about:

          {code:java}
          def repo = checkout scm
          echo repo.GIT_COMMIT
          {code}

          This works correctly for branch builds, but not for merge request builds and the strategy "Merging the merge request with the current target branch revision" - when using that strategy, {{GIT_COMMIT}} points to a revision which doesn't exist after the merge, but instead to the merge commit from the "temporary" chechout which was done for reading the {{Jenkinsfile}}. Relevant log snippets:

          {noformat}
          Branch indexing
          Querying the current revision of merge request #3...
          Current revision of merge request #3 is 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Checking out git https://&lt;REPO&gt;.git into /var/lib/jenkins/workspace/SOMETHING_MR-3@script to read Jenkinsfile
          [...]
           > git fetch --no-tags --force --progress -- https://&lt;REPO&gt;.git +refs/merge-requests/3/head:refs/remotes/origin/MR-3 +refs/heads/master:refs/remotes/origin/master # timeout=10
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing a9473d5a2d79ace679affe37853e74950602b07b
          Checking out Revision a9473d5a2d79ace679affe37853e74950602b07b (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [GitLab Pipeline Status] Notified
          Running in Durability level: PERFORMANCE_OPTIMIZED
          [...]
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [Pipeline] Start of Pipeline
          [...]
          [Pipeline] checkout
          [...]
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing bdabb0071fa91fe128c037a9f3352b459fcfcde8
          Checking out Revision bdabb0071fa91fe128c037a9f3352b459fcfcde8 (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          First time build. Skipping changelog.
          [...]
          [Pipeline] echo
          {GIT_AUTHOR_EMAIL=someidiot@inform-software.com, GIT_AUTHOR_NAME=Test-Jenkins, GIT_BRANCH=feature/update-slf4j, GIT_COMMIT=a9473d5a2d79ace679affe37853e74950602b07b, GIT_COMMITTER_EMAIL=someidiot@inform-software.com, GIT_COMMITTER_NAME=Test-Jenkins, GIT_LOCAL_BRANCH=feature/update-slf4j, GIT_PREVIOUS_COMMIT=873ac16b7ac3b44ad9b45cdde7479a3dd73a4beb, GIT_PREVIOUS_SUCCESSFUL_COMMIT=367f5bc9835cecaf5929cf9a6a8d3600ad1dae32, GIT_URL=https://&lt;REPO&gt;.git}
          [...]
          + git log --oneline -2
          bdabb00 Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD
          eb6a580 Update test output
          [...]
          {noformat}

          Now, with a lightweight checkout:
          {noformat}
          Started by user Tobias Gruetzmacher
          Querying the current revision of merge request #3...
          Current revision of merge request #3 is 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Obtained Jenkinsfile from eb6a5804b1a07157304d00562a489437342049e1+367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Running in Durability level: PERFORMANCE_OPTIMIZED
          [...]
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [GitLab Pipeline Status] Notified
          [Pipeline] Start of Pipeline
          [...]
          [Pipeline] checkout
          [...]
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing 793df539d53a54cb84316c39f81939c344255e4b
          Checking out Revision 793df539d53a54cb84316c39f81939c344255e4b (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          First time build. Skipping changelog.
          [...]
          [Pipeline] echo
          {GIT_AUTHOR_EMAIL=someidiot@inform-software.com, GIT_AUTHOR_NAME=Test-Jenkins, GIT_BRANCH=feature/update-slf4j, GIT_COMMIT=793df539d53a54cb84316c39f81939c344255e4b, GIT_COMMITTER_EMAIL=someidiot@inform-software.com, GIT_COMMITTER_NAME=Test-Jenkins, GIT_LOCAL_BRANCH=feature/update-slf4j, GIT_PREVIOUS_COMMIT=a9473d5a2d79ace679affe37853e74950602b07b, GIT_PREVIOUS_SUCCESSFUL_COMMIT=367f5bc9835cecaf5929cf9a6a8d3600ad1dae32, GIT_URL=https://git.inform-software.com/tgruetzm/versions.git}
          [...]
          + git log --oneline -2
          793df53 Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD
          eb6a580 Update test output
          [...]
          {noformat}
          This issue is just for documentation, since the issue went away with the update to gitlab-branch-source [1.4.4|https://github.com/jenkinsci/gitlab-branch-source-plugin/releases/tag/gitlab-branch-source-1.4.4]. Before that, a merge request would do a "fat" instead a lightweight checkout to read the {{Jenkinsfile}} and I cannot reproduce the issue when just a lightweight checkout is done.

          Pipeline sample code to have something to talk about:

          {code:java}
          def repo = checkout scm
          echo repo.GIT_COMMIT
          {code}

          This works correctly for branch builds, but not for merge request builds and the strategy "Merging the merge request with the current target branch revision" - when using that strategy, {{GIT_COMMIT}} points to a revision which doesn't exist after the merge, but instead to the merge commit from the "temporary" chechout which was done for reading the {{Jenkinsfile}}. Relevant log snippets:

          {noformat}
          Branch indexing
          Querying the current revision of merge request #3...
          Current revision of merge request #3 is 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Checking out git https://&lt;REPO&gt;.git into /var/lib/jenkins/workspace/SOMETHING_MR-3@script to read Jenkinsfile
          [...]
           > git fetch --no-tags --force --progress -- https://&lt;REPO&gt;.git +refs/merge-requests/3/head:refs/remotes/origin/MR-3 +refs/heads/master:refs/remotes/origin/master # timeout=10
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing a9473d5a2d79ace679affe37853e74950602b07b
          Checking out Revision a9473d5a2d79ace679affe37853e74950602b07b (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [GitLab Pipeline Status] Notified
          Running in Durability level: PERFORMANCE_OPTIMIZED
          [...]
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [Pipeline] Start of Pipeline
          [...]
          [Pipeline] checkout
          [...]
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing bdabb0071fa91fe128c037a9f3352b459fcfcde8
          Checking out Revision bdabb0071fa91fe128c037a9f3352b459fcfcde8 (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          First time build. Skipping changelog.
          [...]
          [Pipeline] echo
          {GIT_AUTHOR_EMAIL=xxx, GIT_AUTHOR_NAME=xxx, GIT_BRANCH=feature/update-slf4j, GIT_COMMIT=a9473d5a2d79ace679affe37853e74950602b07b, GIT_COMMITTER_EMAIL=xxx, GIT_COMMITTER_NAME=xxx, GIT_LOCAL_BRANCH=feature/update-slf4j, GIT_PREVIOUS_COMMIT=873ac16b7ac3b44ad9b45cdde7479a3dd73a4beb, GIT_PREVIOUS_SUCCESSFUL_COMMIT=367f5bc9835cecaf5929cf9a6a8d3600ad1dae32, GIT_URL=https://&lt;REPO&gt;.git}
          [...]
          + git log --oneline -2
          bdabb00 Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD
          eb6a580 Update test output
          [...]
          {noformat}

          Now, with a lightweight checkout:
          {noformat}
          Started by user Tobias Gruetzmacher
          Querying the current revision of merge request #3...
          Current revision of merge request #3 is 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Obtained Jenkinsfile from eb6a5804b1a07157304d00562a489437342049e1+367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          Running in Durability level: PERFORMANCE_OPTIMIZED
          [...]
          [GitLab Pipeline Status] Notifying merge request build status: RUNNING tgruetzm/versions/ci/MR-3: Build started...
          [GitLab Pipeline Status] Notified
          [Pipeline] Start of Pipeline
          [...]
          [Pipeline] checkout
          [...]
          Merging remotes/origin/master commit eb6a5804b1a07157304d00562a489437342049e1 into MR head commit 367f5bc9835cecaf5929cf9a6a8d3600ad1dae32
          [...]
          Merge succeeded, producing 793df539d53a54cb84316c39f81939c344255e4b
          Checking out Revision 793df539d53a54cb84316c39f81939c344255e4b (feature/update-slf4j)
          [...]
          Commit message: "Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD"
          First time build. Skipping changelog.
          [...]
          [Pipeline] echo
          {GIT_AUTHOR_EMAIL=xxx, GIT_AUTHOR_NAME=xxx, GIT_BRANCH=feature/update-slf4j, GIT_COMMIT=793df539d53a54cb84316c39f81939c344255e4b, GIT_COMMITTER_EMAIL=xxx, GIT_COMMITTER_NAME=xxx, GIT_LOCAL_BRANCH=feature/update-slf4j, GIT_PREVIOUS_COMMIT=a9473d5a2d79ace679affe37853e74950602b07b, GIT_PREVIOUS_SUCCESSFUL_COMMIT=367f5bc9835cecaf5929cf9a6a8d3600ad1dae32, GIT_URL=https://&lt;REPO&gt;.git}
          [...]
          + git log --oneline -2
          793df53 Merge commit 'eb6a5804b1a07157304d00562a489437342049e1' into HEAD
          eb6a580 Update test output
          [...]
          {noformat}
          markewaite Mark Waite made changes -
          Assignee Mark Waite [ markewaite ]
          markewaite Mark Waite made changes -
          Labels newbie-friendly
          cobexer Ing. Christoph Obexer made changes -
          Priority Minor [ 4 ] Major [ 3 ]
          cobexer Ing. Christoph Obexer made changes -
          Assignee Rick [ surenpi ]

          People

            surenpi Rick
            tgr Tobias Gruetzmacher
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: