How can I access the last built revision according to jenkins?

Viewed 13004

Near the top of my build console I see a "Last Built Revision:" w/ a revision #. How can I access this last built rev # in my build script? I'm using Gradle, but I don't think that matters here. Does Jenkins provide the last built rev # in a system property? Surely this must be trivial to access from my build script...

5 Answers

The Git plugin returns information from the checkout() command. In Pipeline script, this can be used to get the previous commit:

def scmVars = checkout scm

scmVars.GIT_PREVIOUS_COMMIT
Related