[JIRA] (JENKINS-41455) Converting double quoted values in scripts as 'isLiteral'

2 views
Skip to first unread message

kzantow@cloudbees.com (JIRA)

unread,
Jan 25, 2017, 4:37:01 PM1/25/17
to jenkinsc...@googlegroups.com
Keith Zantow created an issue
 
Jenkins / Bug JENKINS-41455
Converting double quoted values in scripts as 'isLiteral'
Issue Type: Bug Bug
Assignee: Andrew Bayer
Components: pipeline-model-definition-plugin
Created: 2017/Jan/25 9:36 PM
Priority: Minor Minor
Reporter: Keith Zantow

Given this pipeline:

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo "hello"
      }
    }
  }
}

Converting to JSON results in the script argument incorrectly labeled as isLiteral: true

{"status":"ok","data":{"result":"success","json":{"pipeline":{"stages":[{"name":"Build","branches":[{"name":"default","steps":[{"name":"echo","arguments":[{"key":"message","value":{"isLiteral":true,"value":"hello"}}]}]}]}],"agent":{"type":"any"}}}}}
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

andrew.bayer@gmail.com (JIRA)

unread,
Jan 25, 2017, 7:23:01 PM1/25/17
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Bug JENKINS-41455
 
Re: Converting double quoted values in scripts as 'isLiteral'

Not entirely sure what the problem is? Admittedly, I'm also still not entirely sure what "isLiteral" really means, so there's that. =)

kzantow@cloudbees.com (JIRA)

unread,
Jan 25, 2017, 9:28:02 PM1/25/17
to jenkinsc...@googlegroups.com

AFAIK it's the difference between double and single quotes in the pipeline script.

So, for example: echo "hello $USER" might print 'hello jenkins' but echo 'hello $USER' might print 'hello apache', as the $USER variable will be resolved at runtime on the node, vs. runtime on the Jenkins server.

andrew.bayer@gmail.com (JIRA)

unread,
Jan 25, 2017, 10:25:01 PM1/25/17
to jenkinsc...@googlegroups.com

Ah. So in the case you included in the description, we should have "hello" inside double quotes in the model representation...

kzantow@cloudbees.com (JIRA)

unread,
Jan 25, 2017, 10:47:03 PM1/25/17
to jenkinsc...@googlegroups.com

No, it should be isLiteral: false. Although it's not going to be in the preview, when JSON -> Jenkinsfile is called, it should result in that argument being double quoted vs. single quoted. I dunno if that's an issue or not, but I should be able to load that, get the JSON with isLiteral: false and then turn around and post it back with a similarly double-quoted result.

kzantow@cloudbees.com (JIRA)

unread,
Jan 25, 2017, 10:48:01 PM1/25/17
to jenkinsc...@googlegroups.com
Keith Zantow edited a comment on Bug JENKINS-41455
No, it should be _isLiteral: false_. Although it's setting _isLiteral: false_ is not going to be in the editor preview, it probably will be eventually, and when JSON -> Jenkinsfile is called, it should result in that argument being double quoted vs. single quoted. I dunno if that's an issue or not, but I should be able to load that, get the JSON with _isLiteral: false_ and then turn around and post it back with a similarly double-quoted result.

andrew.bayer@gmail.com (JIRA)

unread,
Jan 26, 2017, 11:17:01 AM1/26/17
to jenkinsc...@googlegroups.com

So in this case, it should be isLiteral: true - parseArgument looks to see whether the expression is a constant or GString. "hello" is a constant, 'echo $HELLO' is a constant, "echo $HELLO" is a GString. If it's a GString, isLiteral is set to false, otherwise it's set to true.

andrew.bayer@gmail.com (JIRA)

unread,
Jan 26, 2017, 11:23:01 AM1/26/17
to jenkinsc...@googlegroups.com

Double-checked it, and...

  • sh 'echo "FOO is $FOO"' becomes
                    {
              "name": "sh",
              "arguments": [          {
                "key": "script",
                "value":             {
                  "isLiteral": true,
                  "value": "echo \"FOO is $FOO\""
                }
              }]
            },
    
  • echo "Foo is $FOO" becomes
                    {
              
  • "name": "echo",
              "arguments": [          {
                "key": "message",
                "value"
  • :             {
                  "isLiteral": false,
                  "value": "Foo is $FOO"
                }
              }]
            }
    

andrew.bayer@gmail.com (JIRA)

unread,
Jan 26, 2017, 11:32:01 AM1/26/17
to jenkinsc...@googlegroups.com

Important point here - we have no way of telling the difference between 'hello' and "hello" - but then, it doesn't matter because they're not actually different. They're both just Strings. What matters is that we can distinguish between 'hello $WORLD' and "hello $WORLD", and that we do.

kzantow@cloudbees.com (JIRA)

unread,
Jan 26, 2017, 11:52:01 AM1/26/17
to jenkinsc...@googlegroups.com

Ah, perfect explanation. Functionally equivalent is fine by me.

andrew.bayer@gmail.com (JIRA)

unread,
Jan 26, 2017, 11:56:01 AM1/26/17
to jenkinsc...@googlegroups.com

Yeah, the only difference between single-quote and double-quote strings in Groovy is parse-time handling - i.e., whether to parse it as a String or a GString. So woot.

andrew.bayer@gmail.com (JIRA)

unread,
Jan 26, 2017, 11:57:02 AM1/26/17
to jenkinsc...@googlegroups.com
Andrew Bayer resolved as Not A Defect
 
Change By: Andrew Bayer
Status: Open Resolved
Resolution: Not A Defect

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:24:34 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Not A Defect
 

Bulk closing resolved issues.

Change By: Liam Newman
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages