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

sh step does not parse dollar slashy string literal

XMLWordPrintable

      The sh step fails when the script is passed as a dollar slashy string literal. A minimal example is:

      pipeline {
          agent any
          stages {
              stage('Test') {
                  steps {
                      sh $/
                          echo 'Could read the dollar-slashy string!'
                      /$
                  }
              }
          }
      }
      

      This pipeline fails with the following error:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      WorkflowScript: 14: unexpected char: 0xFFFF @ line 14, column 1.
      1 error
      
      	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)
      	at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:149)
      	at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:119)
      	at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:131)
      	at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:349)
      	at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:220)
      	at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:191)
      	at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:233)
      	at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:189)
      	at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:966)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:626)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:602)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:579)
      	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:323)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:293)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox$Scope.parse(GroovySandbox.java:163)
      	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:190)
      	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:175)
      	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:636)
      	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:582)
      	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:335)
      	at hudson.model.ResourceController.execute(ResourceController.java:101)
      	at hudson.model.Executor.run(Executor.java:442)
      Finished: FAILURE
      

      Interestingly, when the string literal is assigned to a variable which then is passed to the sh step (def script = $/.../$; sh script;), or the parameter name is added (sh script: $/.../$), it works.

            Unassigned Unassigned
            f1rstlady Benedikt
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: