-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
Jenkins ver. 2.193
Pipeline-Groovy plugin: v2.74.
All plugins up-to date, as of today.
We have defined a map, with keys consisting of some predefined string which should be concatenated with the content of same variable. We use the parentheses to allow the key to be resolved with variable replacement. Printing the map, yields the correct entries for both the keys and their values.
The problem is when trying to access any item in the map directly, eg: println mymap["myKey1"]. This would wrongly return null instead of the real value.
Simplified sample code for a Jenkins pipeline, to reproduce the issue:
```
node("my-node") {
stage('Reproducing the issue') {
MYVAR="ZZ"
FIRSTELEMKAY="prefix1"+MYVAR
def testmap = [("prefix1${MYVAR}"): "content1", ("prefix2${MYVAR}"): "content2"]
println "[1] Reproducing the issue.."
println "[1][Fine] Print map as is: " + testmap
println "[1][Fine] Print map keys: " + testmap.keySet()
//println "[1][Fine] Print map first key: " + testmap.keySet()[0]
//println "[1][Wrong] Print the content of the first entry in the map: " + testmap[testmap.keySet()[0]]
println "[1][Wrong] Print the content of the first entry in the map ($FIRSTELEMKAY): " + testmap[FIRSTELEMKAY]
println "[1] The keys seem to have been populated with the expected values, BUT the find operation returns 'null' instead of the real content."
}
stage('WA Code')
{ MYVAR="ZZ" def testmap = [("prefix1"+MYVAR): "content1", ("prefix2"+MYVAR): "content2"] println "[2] Some WA for the issue.." println "[2][Fine] Print map as is: " + testmap println "[2][Fine] Print map keys: " + testmap.keySet() //println "[2][Fine] Print map first key: " + testmap.keySet()[0] //println "[2][Fine] Print the content of the first entry in the map: " + testmap[testmap.keySet()[0]] println "[2][Fine] Print the content of the first entry in the map ($FIRSTELEMKAY): " + testmap[FIRSTELEMKAY] println "[2] The keys seem to have been populated with the expected values, the find operation returns the real content." }}
```