For a project I would like to know which branch is used to check out the pipeline script that is used. In this case I would get back that the branch is */develop
Job Definition example
Solved by using this:
String url = 'curl --user ' + "${JENKINS_USER}:${JENKINS_PASS}" + ' https://jenkinsurl/job/'+ env.JOB_NAME + '/config.xml' String CICD_BRANCH = new XmlSlurper().parseText(url.execute().text).definition.scm.branches."hudson.plugins.git.BranchSpec".getProperty("name").toString().substring(2); env.CICDBRANCH = CICD_BRANCH.toString()
To get the current branch name in your pipline script you can use the below code.
branch name
pipline
echo "My branch is: ${scm.branches[0]}" node('build_node') { }
2.1m questions
2.1m answers
60 comments
57.0k users