[JIRA] (JENKINS-59179) map variable replacement for keys - cannot retrieve values back

5 views
Skip to first unread message

uliul.carpatin@gmail.com (JIRA)

unread,
Sep 2, 2019, 6:45:03 AM9/2/19
to jenkinsc...@googlegroups.com
Uliul Carpatin created an issue
 
Jenkins / Bug JENKINS-59179
map variable replacement for keys - cannot retrieve values back
Issue Type: Bug Bug
Assignee: Unassigned
Components: pipeline-build-step-plugin
Created: 2019-09-02 10:44
Environment: Jenkins ver. 2.193
Pipeline-Groovy plugin: v2.74.
All plugins up-to date, as of today.
Priority: Major Major
Reporter: Uliul Carpatin

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("slave-loop") {
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." }

}

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

uliul.carpatin@gmail.com (JIRA)

unread,
Sep 2, 2019, 6:47:03 AM9/2/19
to jenkinsc...@googlegroups.com
Uliul Carpatin updated an issue
Change By: Uliul Carpatin
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(" slave my - loop 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." }

}


 

uliul.carpatin@gmail.com (JIRA)

unread,
Sep 2, 2019, 6:48:01 AM9/2/19
to jenkinsc...@googlegroups.com
Uliul Carpatin updated an issue
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." }

}
```

 
Reply all
Reply to author
Forward
0 new messages