Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48271

Strings with exclamation mark passed to sh step get single quoted

    Details

    • Similar Issues:

      Description

      Using this as a minimal example:

       

      script {
          def testString1 = "echo a="
          def testString2 = "!123"
          def testString3 = "b="
          def testString4 = "2937"
      
          print "testString1+2 = "+testString1+testString2
          print "testString3+4 = "+testString3+testString4
          print "total: "+testString1+testString2+testString3+testString4
      
          sh "echo ${testString1}${testString2}"
          sh "eval ${testString1}${testString2}"
          
          sh "echo ${testString1}${testString2} ${testString3}${testString4}"
          sh "eval ${testString1}${testString2} ${testString3}${testString4}"
      }
      

       

      The result while running the pipeline is:

       

      
      [Pipeline] script
      [Pipeline] {
      [Pipeline] echo
      testString1+2 = echo a=!123
      [Pipeline] echo
      testString3+4 = b=2937
      [Pipeline] echo
      total: echo a=!123b=2937
      [Pipeline] sh
      [pipeName] Running shell script
      + echo echo 'a=!123'
      echo a=!123
      [Pipeline] sh
      [pipeName] Running shell script
      + eval echo 'a=!123'
      ++ echo 'a=!123'
      a=!123
      [Pipeline] sh
      [pipeName] Running shell script
      + echo echo 'a=!123' b=2937
      echo a=!123 b=2937
      [Pipeline] sh
      [pipeName] Running shell script
      + eval echo 'a=!123' b=2937
      ++ echo 'a=!123' b=2937
      a=!123 b=2937
      [Pipeline] }
      [Pipeline] // script
      

       

      Notice that last echo treats strings differently depending on whether or not the exclamation mark is contained within a contiguous string.

      This creates issues when, for example, creating maven options dynamically at runtime. Trying to generate 

      -Dopt1=test -Dopt2=test!1

       leads to a string

      -Dopt1=test '-Dopt2=test!1'

      which then doesn't work.

      This treatment of strings lacking consistency, and despite all my efforts to try to trim the string (or create the string within a shell script, etc), ultimately this issue is a bottleneck.

      Let me know if I am missing something, I will happily provide more information if needed.

       

       

       

        Attachments

          Activity

          cmehdy Mehdy Chaillou created issue -
          abayer Andrew Bayer made changes -
          Field Original Value New Value
          Component/s pipeline-model-definition-plugin [ 21706 ]
          Component/s pipeline [ 21692 ]
          abayer Andrew Bayer made changes -
          Assignee Andrew Bayer [ abayer ]
          abayer Andrew Bayer made changes -
          Component/s workflow-durable-task-step-plugin [ 21715 ]
          Component/s pipeline-model-definition-plugin [ 21706 ]
          abayer Andrew Bayer made changes -
          Assignee Andrew Bayer [ abayer ]
          abayer Andrew Bayer made changes -
          Summary Declarative Pipelines: Strings with exclamation mark get single quoted Strings with exclamation mark passed to sh step get single quoted
          cmehdy Mehdy Chaillou made changes -
          Attachment image-2017-11-29-16-40-26-819.png [ 40536 ]
          abayer Andrew Bayer made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Not A Defect [ 7 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              cmehdy Mehdy Chaillou
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: