I am wondering is there any way we can pass the value of project parameter as the Git branch to build from.
Below is what I am trying to do:
However the branch_name variable is not resolved from the project parameter.
I could do manually change branch name for every build, but it is far from ideal.
Appreciate for any idea?
Head over to your Jenkins instance and create a new item. Enter a name for the job, and select the “Multibranch Pipeline” option at the end of the screen. Then, click on the OK button. In the next screen, go to the “Branch sources” tab, click on the “Add source” button, and choose “Git” from the dropdown menu.
To use the branch in a build I typically name the parameter "branch" and then under "Source Code Management" (with Git selected) use "${branch}" (without the quotes) for the "Branches to build" "Branch Specifier (blank for 'any')" field. Hope that helps.
Defining Build Parameters Any Jenkins job or pipeline can be parameterized. All we need to do is check the box on the General settings tab, “This project is parameterized”: Then we click the Add Parameter button.
This issue has been reported several times. This works if you disable the "Lightweight Checkout". Apparently the code path is very different if you are using the lightweight checkout, and that has not been resolved, apparently.
See JENKINS-28447
You can use git parameter plugin ...
then in paramerterized select Git Paramerter ..Give any Name e.g. BRANCH select parameter type as "Branch" and put default value for branch. Then in Branches to build inthat put ${BRANCH}. Build job with parameter as 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