-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
Jenkins 2.107.2
Pipeline 2.5
Pipeline-groovy 2.49
It is not possible to add multiple objects to a list and join them to a string.
Only the first added object will be in the output string.
This code snippert works perfectly fine in normal groovy, but not with jenkins groovy :-/
class TemplateParameter implements Serializable {
final String parameter
final String value
TemplateParameter(String parameter, String value) {
assert parameter
this.parameter = parameter.toUpperCase()
assert value
this.value=value
}
String toString() {
"-p=$parameter=$value"
}
}
node('master') {
def branch = 'foobar'
def revision = '1337'
List<TemplateParameter> result = []
result += new TemplateParameter('rev', revision)
result += new TemplateParameter('branch', branch)
println "[DEBUG] Template Parameters size: ${result.size()}"
println "[DEBUG] Template Parameters: ${result.join(' ')}"
}
Output:
[Pipeline] {
[Pipeline] echo
[DEBUG] Template Parameters size: 2
[Pipeline] echo
[DEBUG] Template Parameters: -p=REV=1337
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Expected:
[DEBUG] Template Parameters size: 2
[DEBUG] Template Parameters: -p=REV=1337 -p=BRANCH=foobar
I'll check when I get a chance to see why += isn't working, but, fwiw, someList << someObject or someList.add(someObject) will work fine.