In a multibranch pipeline, there is an option to build PR merged with the base branch. When this option is enabled GIT_COMMIT environment variable contains the hash of the merged commit not the hash of the last hash of the change branch. There is no other environment variable set with the branch revision hash.
But I want the hash of the branch revision to run Sonar PR analysis and for some other reporting tasks. How can I achieve this?
https://issues.jenkins-ci.org/browse/JENKINS-39496 describes about PullRequestSCMRevision. But I have no idea on how to call the PullRequestSCMRevision.getPullHash() function inside a Jenkinsfile in a declarative pipeline.
git rev-parse PRBRANCHNAMEHERE
to get the actual commit of the PR branch rather than the temporary merge commit. – Omer Tuchfeldgit rev-parse PRBRANCHNAMEHERE
worked for me. Thanks a lot for the point. – Dulaj Atapattu