Issue
I have a parameterized Jenkins pipeline build. One of the parameters (branch) is the branch to build. The pipeline file is stored in the branch.
In the Pipeline definition, when I use */${branch}
as the branch to build in place of */main
the ${branch}
does not get replaced but shows up as a literal. If I hard code the branch it works as expected.
The ${branch}
does get replaced as expected in the pipeline file. So the branch
parameter is being set.
Is there a way to get the parameter value into the "Pipeline script from SCM" retrieval from git?
Solution
You can try another approach as following:
In pipeline configuration page, change pipeline from SCM to pipeline script
Put following pipeline script in input box
node('<Jenkins node label>') {
properties([
parameters([
// parameter for branch
])
])
git url: '', credentailId:'', branch: "${branch}"
load '<relative path to your Jenkinsfile>'
}
Answered By - yong
Answer Checked By - David Marino (JavaFixing Volunteer)