Question: Is there any way to get the name of the branch that is checkout by the Pipeline in a jenkinsfile?
NOTE: I am not in a Multibranch Pipeline!
In my pipeline im using
checkout([$class: 'GitSCM',
userRemoteConfigs: [[url:'https://github.com/repo',
credentialsId: 'xxxx',name: '1234']]])
where name
is the commit ID. I need to verify that this commit id is from the branch that a user has specified as parameter (user specifies both branch name and commit id and I need to check if there is no error before building the project).
Why is the branch name not exposed in Pipeline but only in Multibranch Pipeline? Doesn't make sense to me.
There are three reasons why I don't want to convert to the multi branch pipeline:
I have printed out all environment variables, branch name is not among them.
Thanks for the help!
if you are using pipeline code I assume you are doing something like:
checkout scm
Nice thing is this returns a map with some useful stuff from which you can grab the checked out branch in the following manner:
def scmVars = checkout scm
def branchName = scmVars.GIT_BRANCH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With