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
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()
question from:https://stackoverflow.com/questions/65829369/access-jenkins-pipeline-definition-within-jenkinsfile