As you can see in the attached screenshot, I want my pipeline to fetch the Jenkinsfile from the same branch that is passed in as a parameter and saved in the BRANCH_NAME
variable:
When the pipeline build starts, Jenkins uses the Jenkinsfile in that branch for build stages. SCM (Source Control) can be Github, Bitbucket, or a Gitlab repo. You can choose to exclude selected branches if you don't want them to be in the automated pipeline with Java regular expressions.
Login to your Jenkins installation and go you your job and click configure. In the Source Code Management section under Build Triggers check the Generic Webhook Trigger. Click Add next to the Post content parameters. Once a push is made, GitHub passes the branch name in the JSON format with the ref key.
Summary. This plugin provides a Build Pipeline View of upstream and downstream connected jobs that typically form a build pipeline. In addition, it offers the ability to define manual triggers for jobs that require intervention prior to execution, e.g. an approval process outside of Jenkins.
Click New Item on your Jenkins home page, enter a name for your (pipeline) job, select Pipeline, and click OK. In the Script text area of the configuration screen, enter your pipeline syntax.
I had to uncheck "Lightweight checkout" to make Jenkins parse the ${BRANCH_NAME} parameter under the Pipeline SCM settings:
See below:
checkout([$class: 'GitSCM', branches: [[name: "${BRANCH_NAME}"]], [[credentialsId: 'CRED_ID', url: 'https://url.goes.here']]])
To be more explicit, you could use ${params.BRANCH_NAME}
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