I'm using Jenkins multibranch pipelines.
I want to get the Git hash before the pipeline even starts and wondering if the data is available in some system class or variable. I don't want to shell out to the git
command nor have to wait till the checkout scm
step is executed and then read properties of that object.
Perhaps this is impossible, but it does seem like I can get a list of changed files before the check step and pipeline directive with currentBuild.changeSets
like this: Which Jenkins Command to Get the List of Changed Files.
What other secrets does currentBuild
greedily hide from me? Does it have a method that could retrieve the current git hash of the branch- again before the checkout step the runs inside the pipeline?
Also, to add why I think this is possible, I see this console output whenever a multibranch job starts:
Started by user me
Obtained mydir/Jenkinsfile from <FULL GIT HASH OF COMMIT>
Running in Durability level: MAX_SURVIVABILITY
.....
So clearly Jenkins gets the hash of the commit immediately. I'm hoping it's possible to retrieve in code.