Hi, We are trying to simplify integration of SonarQube with most popular pull request provider, like GitHub or Bitbucket. Those ALM usually provide some API to report issues on PR (GitHub checks, Bitbucket Code Insight, ...). The APIs require to pass the PR HEAD commit sha1.
We are trying to get this commit ref automatically when the SonarQube scanner is executed in a Jenkins pipeline. The problem I'm facing is that Jenkins is creating a local merge of the PR head with the PR base branch, and the value of GIT_COMMIT is the ref of this local transcient commit, which is pretty useless for reporting back to the ALM. Example: For PR with HEAD at ab86fe3afa0b9473ea9da76c87872bf89b9b5f3b: [image: image.png] Using this pipeline: node { stage 'Checkout' def scmVars = checkout scm def commitHash = scmVars.GIT_COMMIT println commitHash } Produces this log: > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://github.com/henryju/test-jenkins.git # timeout=10 Fetching without tags Fetching upstream changes from https://github.com/henryju/test-jenkins.git > git --version # timeout=10 using GIT_ASKPASS to set credentials > git fetch --no-tags --force --progress https://github.com/henryju/test-jenkins.git +refs/pull/1/head:refs/remotes/origin/PR-1 +refs/heads/master:refs/remotes/origin/master Merging remotes/origin/master commit 57ff7166357a4939da69bc43db84961536557c21 into PR head commit ab86fe3afa0b9473ea9da76c87872bf89b9b5f3b > git config core.sparsecheckout # timeout=10 > git checkout -f ab86fe3afa0b9473ea9da76c87872bf89b9b5f3b > git merge 57ff7166357a4939da69bc43db84961536557c21 # timeout=10 > git rev-parse HEAD^{commit} # timeout=10 Merge succeeded, producing 6a95262014cca41cf11e810401bd5c1bc0954515 Checking out Revision 6a95262014cca41cf11e810401bd5c1bc0954515 (PR-1) > git config core.sparsecheckout # timeout=10 > git checkout -f 6a95262014cca41cf11e810401bd5c1bc0954515 Commit message: "Merge commit '57ff7166357a4939da69bc43db84961536557c21' into HEAD" > git rev-list --no-walk ab86fe3afa0b9473ea9da76c87872bf89b9b5f3b # timeout=10 GIT_COMMIT will return 6a95262014cca41cf11e810401bd5c1bc0954515 while this is useless for reporting issues in GitHub. Is there any simple way (except some fragile local Git operation) to access the original Git sha1 that triggered the PR build? In my example I need to get ab86fe3afa0b9473ea9da76c87872bf89b9b5f3b Note that I have the same need with the Bitbucket Branch Source Plugin. Thanks, Julien Henry | SonarSource Developer https://sonarsource.com -- You received this message because you are subscribed to the Google Groups "Jenkins Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAD9wyxE5J9JN5H%2BToScP-vjudgoj3B59sRn07SrQtvr4uOiy3Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.