I have a Jenkins with the Github organization plugin that scans my organization and build all the branches/PRs of all the repositories within the organization that have a Jenkinsfile.
It works great, but I would like to retrieve for each build the commit SHA, in order to tag Docker images with both the branch name and the commit SHA.
Getting the branch name works great with env.BRANCH_NAME
, however I cannot find any way to get the commit SHA.
The catch is that we are using JGit, so I cannot use git log
to retrieve it.
I tried having a look at what is contained in the ENV using sh 'printenv'
, but there's nothing of any use there.
I also tried the following:
def checkoutResults = checkout scm
echo 'checkout results: ' + checkoutResults
but this yields the following result:
checkout results: [:]
Even though I cannot get the revision from my pipeline, Jenkins is getting it alright, as I can see in the logs:
...
Obtained Jenkinsfile from 98062e5f651ca698f4303c3bb8d20665ce491294
...
Checking out Revision 98062e5f651ca698f4303c3bb8d20665ce491294 (docker)
I am running the following versions:
- Jenkins 2.73.3
Git plugin
plugin 3.3.0Pipeline: SCM Step
plugin 2.6
Would appreciate any help in retrieving the commit SHA / revision in this particular situation.