[JIRA] (JENKINS-27916) GString not flattened to String by DSL inside a map

1 view
Skip to first unread message

frederic.chuong@gmail.com (JIRA)

unread,
Jun 24, 2016, 11:26:03 AM6/24/16
to jenkinsc...@googlegroups.com
Frédéric Chuong commented on Bug JENKINS-27916
 
Re: GString not flattened to String by DSL inside a map

In Groovy, you have to escape symbols for map literals keys:

[(requiredFile): 'xxx']

http://groovy-lang.org/groovy-dev-kit.html#_map_literals :

Map keys are strings by default: [a:1] is equivalent to ['a':1]. This can be confusing if you define a variable named a and that you want the value of a to be the key in your map. If this is the case, then you must escape the key by adding parenthesis

That means the workaround of using a GString as a key should not be needed

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

jacob.keller@gmail.com (JIRA)

unread,
Jul 8, 2016, 7:05:02 PM7/8/16
to jenkinsc...@googlegroups.com

The above does not work and still generates the exception:

def file = "name-$

{env.BUILD_NUMBER}

"
[(file) : "."] still results in

java.lang.ClassCastException: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String
at org.jenkinsci.plugins.workflow.steps.ArtifactUnarchiverStepExecution.run(ArtifactUnarchiverStepExecution.java:44)
at org.jenkinsci.plugins.workflow.steps.ArtifactUnarchiverStepExecution.run(ArtifactUnarchiverStepExecution.java:20)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:49)
at hudson.security.ACL.impersonate(ACL.java:213)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

justinrainwater78@gmail.com (JIRA)

unread,
Jul 20, 2016, 5:58:02 PM7/20/16
to jenkinsc...@googlegroups.com

I found this thread because I was running into the exact same error. I was able to get it working by adding .toString() along with the () in the mapping.

So in this case it would be:
def file = "name-$

{env.BUILD_NUMBER}

".toString()
[(file) : "."]

HTH

jglick@cloudbees.com (JIRA)

unread,
Aug 29, 2016, 1:54:01 PM8/29/16
to jenkinsc...@googlegroups.com
Jesse Glick updated an issue
 
Jenkins / Bug JENKINS-27916
Change By: Jesse Glick
Component/s: workflow-cps-plugin
Component/s: pipeline

scm_issue_link@java.net (JIRA)

unread,
Feb 13, 2018, 1:24:05 PM2/13/18
to jenkinsc...@googlegroups.com
SCM/JIRA link daemon commented on Bug JENKINS-27916
 
Re: GString not flattened to String by DSL inside a map

Code changed in jenkins
User: Andrew Bayer
Path:
src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinition2Test.java
http://jenkins-ci.org/commit/workflow-cps-plugin/329f900d776c96f4f91576bb7bda3bbde31a26e1
Log:
JENKINS-27916 Test verifying use of GStrings in map keys

This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages