• Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • workflow-cps-plugin
    • None
    • Tested with a fresh, default install of Jenkins 2.42

      A Multibranch Pipeline fails reading a Jenkinsfile if the file is encoded in UTF-8 and includes a BOM (Byte order mark).

      The error depends on the content of the file, but often shows as a variant of 'No such DSL method XX found'.

      If the BOM is removed, the file works fine.

        1. Jenkinsfile
          0.0 kB
        2. Jenkinsfile
          0.1 kB

          [JENKINS-41476] Jenkinsfile fails with BOM

          Éric Louvard added a comment -

          Hier is a Stacktrace wenn the Groovy file contains a BOM and begins with the groovy file marker (#!groovy)
          It seams the the whole file will be parsed without the BOM has been removed before.

          org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
          WorkflowScript: 1: unexpected char: '#' @ line 1, column 2.
             #!groovy
              ^
          
          1 error
          
          	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
          	at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
          	at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120)
          	at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132)
          	at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:350)
          	at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:139)
          	at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:110)
          	at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:234)
          	at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:168)
          	at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:943)
          	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
          	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
          	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
          	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
          	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
          	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
          	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
          	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:67)
          	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:430)
          	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:393)
          	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:238)
          	at hudson.model.ResourceController.execute(ResourceController.java:97)
          	at hudson.model.Executor.run(Executor.java:405)
          Finished: FAILURE
          

          Éric Louvard added a comment - Hier is a Stacktrace wenn the Groovy file contains a BOM and begins with the groovy file marker ( #!groovy ) It seams the the whole file will be parsed without the BOM has been removed before. org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 1: unexpected char : '#' @ line 1, column 2. #!groovy ^ 1 error at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150) at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120) at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132) at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:350) at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:139) at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:110) at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:234) at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:168) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:943) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) at groovy.lang.GroovyShell.parse(GroovyShell.java:700) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:67) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:430) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:393) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:238) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:405) Finished: FAILURE

          Andrew Bayer added a comment -

          Can you attach a Jenkinsfile that's failing for you?

          Andrew Bayer added a comment - Can you attach a Jenkinsfile that's failing for you?

          Éric Louvard added a comment -

          I could reproduce this Issue with Jenkins 2.109 and the attached file Jenkinsfile
          Regards.

          Éric Louvard added a comment - I could reproduce this Issue with Jenkins 2.109 and the attached file Jenkinsfile Regards.

          Harald Albers added a comment - - edited

          I could reproduce this with a simple Jenkinsfile that just contains "echo 'Hello-World!'".
          See attached file Jenkinsfile.

          Steps to reproduce

          1. Add the attached Jenkinsfile to a GIT repo.
          2. Create a Pipeline Job.
          3. Set Definition to "Pipeline script from SCM".
          4. Set "SCM "to "Git", configure the repository and point "Script Path" to the Jenkinsfile.

          If the file has a UTF-8-BOM, the Job fails with

          java.lang.NoSuchMethodError: No such DSL method 'echo' found among steps [archive, bat, ... zip] or globals [currentBuild, docker, env, params, pipeline, scm]
          

          Remove the BOM, check in, push and the job will run as expected.

          Tested with Jenkins ver. 2.176.1

          Harald Albers added a comment - - edited I could reproduce this with a simple Jenkinsfile that just contains "echo 'Hello-World!'". See attached file Jenkinsfile . Steps to reproduce Add the attached Jenkinsfile to a GIT repo. Create a Pipeline Job. Set Definition to "Pipeline script from SCM". Set "SCM "to "Git", configure the repository and point "Script Path" to the Jenkinsfile. If the file has a UTF-8-BOM, the Job fails with java.lang.NoSuchMethodError: No such DSL method 'echo' found among steps [archive, bat, ... zip] or globals [currentBuild, docker, env, params, pipeline, scm] Remove the BOM, check in, push and the job will run as expected. Tested with Jenkins ver. 2.176.1

          Harald Albers added a comment - - edited

          I increased priority for this issue because it now has a wider scope: any pipeline job can be affected, and the cause can be hard to find.

          As an example, I have a production job that fails with

          groovy.lang.MissingPropertyException: No such property:  for class: groovy.lang.Binding
          

          Harald Albers added a comment - - edited I increased priority for this issue because it now has a wider scope: any pipeline job can be affected, and the cause can be hard to find. As an example, I have a production job that fails with groovy.lang.MissingPropertyException: No such property:  for class: groovy.lang.Binding

          Just pinging to say this still exists in Jenkins 2.289, we ran into this yesterday.

          James Hollowell added a comment - Just pinging to say this still exists in Jenkins 2.289, we ran into this yesterday.

            Unassigned Unassigned
            larsskj Lars Skjærlund
            Votes:
            4 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: