I have a Pipeline jenkins job with a checkout step that I want to modify to accept the branch as a parameter.
Currently, this is how we checkout:
stage('Prepare'){
steps {
checkout([$class: 'SubversionSCM', "..." remote: 'http://svn.xxx.bbb/svn/yyy/branches/version_2017']]])
}
}
I would like to change the checkout to something like :
checkout([$class: 'SubversionSCM', "..." remote: 'http://svn.xxx.bbb/svn/yyy/params.BRANCH/params.VERSION']]])
Anyone has done something similar? I can't figure out if it is possible to concatenate a string with job parameters.
Groovy - Concatenation of Strings The concatenation of strings can be done by the simple '+' operator. Parameters − The parameters will be 2 strings as the left and right operand for the + operator.
In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect. let myPet = 'seahorse'; console.
You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.
The thing you're missing is Groovy's String Interpolation: Inside double-quoted strings, ${..}
allows you to include groovy code:
def test = 'world'
println "hello ${test}" // prints hello world
println 'hello ${test}' // prints hello ${test}
So in your example, use
remote: "http://svn.xxx.bbb/svn/yyy/${params.BRANCH}/${params.VERSION}"
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