Search code examples
jenkins-pipeline

How to interpret error messages from Jenkins compiler?


(Apologies for such a general subject - I wanted to reflect the quality of the problem I'm dealing with.)

A scripted pipeline that I wrote fails to even start with this error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 172: expecting ''', found '\n' @ line 172, column 89.
              echo "bt=|${bt}|10"
                                 ^

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 groovy.lang.GroovyShell.parseClass(GroovyShell.java:677)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:689)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:513)
    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

I think I may have complained about the lack of information that the verbose errors in Jenkins leave us with and this seems to be another case: I can't see what's going wrong :((

I spare u the entire script and will just post the lines leading to 172 (and a few more):

....
                    } else {
                        bt = 'bootstrap nul\n'
                        echo "bt=|${bt}|1"
                        bt = bt + "\u2395 SE.SALT.Load'HttpCommand'\n"
                        echo "bt=|${bt}|2"
                        bt = bt + "r\u8592 HttpCommand.Get '${GITHUB}Dyalog/CITA/blob/Authentication/checkout.aplf'\n"
                        echo "bt=|${bt}|3"
                        bt = bt + ':if 0=r.rc\n'
                        echo "xbt=|${bt}|4"  // <---- THIS IS LINE 172!!!
                        bt = bt + " (r.Data 'UTF-8')\u2395 NPUT './checkout.aplf'\n"
                        echo "bt=|${bt}|5"
                        bt = bt + ' \u2395 OFF 0\n'
                        echo "bt=|${bt}|6"
                        bt = bt + ':else\n'
                        echo "bt=|${bt}|7"
                        bt = bt + ' \u2395 \u8592 r\n'
                        echo "bt=|${bt}|8"
                        bt = bt + ' \u2395 OFF 1\n'
                        echo "bt=|${bt}|9"
                        bt = bt + ':endif\n'
                        echo "bt=|${bt}|10"
                        writeFile(file: './bootstrap.aplf', text: bt)

...

The code in 172 was used before (and after, too) and I don't see a fault with it. Also note that the code that is quoted in the message does not come from line 172 but 184 instead. This could ofc indicate that the problem started in 172 - but as I said, all looks good (to me, at least). Also, I think that column 89 is suspicious - we're far away from 89 in this block of code. So I just don't know what to take from this message...

Update1:

I've made some progress! I rewrote a bit, commented out the entire block and activated again - line by line - and executed. Thing started to go wrong when I enabled this line:

code = code + ':if res.rc=0\n'

and the error is:

WorkflowScript: 177: expecting '}', found 'OFF' @ line 177, column 99.
        // code = code + quad + 'OFF z\n'
                                 ^

1 error

I must admit - I don't see the fault there. Nor does the GroovyLinter. Will now tweak this line to find the issue - but am curious about any additional feedback and grateful for reply that solves this mystery!

The fix

Ok, so I found it - the script is runnin! ':bla' causes trouble, ':' + 'bla' does not. Also '\:bla' is fine. Bottom line: the : character needs to be escaped!

BUT

I also found this line in my code:

     string dcfg = '{\"Settings\":\n {\n'

That colon did not cause any trouble! So I'd be VERY interested to know more...


Solution

  • Rewriting that code ultimately fixed the issue for me. Unfortunately I'm no better than Jenkins, because I can't say what reason I found for that error. Also I could not repro issues related to the ':'.