I have a declarative Jenkins pipeline in my Jenkinsfile. I want to be able to do some logic based on the last commit that built successfully for that branch versus the current HEAD of the same branch.
I am using the standard declarative checkout in a Jenkins multibranch pipeline. Each branch has a copy of the Jenkinsfile.
What I have tried
- Using the environment variables exposed by the Git module. This did not work. The variables are not exposed in the pipeline.
- Digging through the internals of the injected currentBuild variable. The method I need to get the revision is unfortunately private and inaccessible. Whitelisting the internal build object that currentBuild wraps would gain me nothing (and yes I tried this). The same method is called by the thing that sets the environment variables.
What is the approach here? I would like to retain the declarative checkout since it automatically chooses the correct branch