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

Workflow parse exception with new approach for unstable stages

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: pipeline
    • Labels:
      None
    • Environment:
      Jenkins 2.176.1
    • Similar Issues:

      Description

      I am following https://jenkins.io/blog/2019/07/05/jenkins-pipeline-stage-result-visualization-improvements/ blogpost to use the new try/catch approach:

      stages {
              stage ('Tests: EN'){
                steps{
                  try {
                    sh 'HOME=$(pwd) bundle && HOME=$(pwd) LOCALE=en BROWSER=chrome-headless-nogpu cucumber --format json --out reports/en.json'
                  }
                  catch (ex) {
                    unstable('Tests failed!')
                  }
                }
              } 

      for marking the results unstable but I'm getting:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      WorkflowScript: 21: Expected a step @ line 21, column 13.
                     try {
                     ^
      
      WorkflowScript: 32: Expected a step @ line 32, column 13.
                     try{
                     ^
      
      WorkflowScript: 43: Expected a step @ line 43, column 13.
                     try{
                     ^
      
      3 errors
      
      	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
      	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.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:522)
      	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:320)
      	at hudson.model.ResourceController.execute(ResourceController.java:97)
      	at hudson.model.Executor.run(Executor.java:429)
      Finished: FAILURE
      

      Jenkins versions and plugin versions are all up to date as in the post.

        Attachments

          Issue Links

            Activity

            Hide
            warden Radek Antoniuk added a comment -

            Got it, thanks!

            Show
            warden Radek Antoniuk added a comment - Got it, thanks!
            Hide
            dnusbaum Devin Nusbaum added a comment -

            Radek Antoniuk try/catch is raw Groovy, you cannot use it in Declarative outside of a script block. Use the warnError or catchError step instead of unstable, as in the first example here:

            stage ('Tests: EN'){
              steps{
                warnError('Tests failed!') {
                  sh 'HOME=$(pwd) bundle && HOME=$(pwd) LOCALE=en BROWSER=chrome-headless-nogpu cucumber --format json --out reports/en.json'
                }
              }
            } 
            

            I will try to update the blog post to explicitly mention that the try/catch example only applies for scripted Pipelines.

            Show
            dnusbaum Devin Nusbaum added a comment - Radek Antoniuk try/catch is raw Groovy, you cannot use it in Declarative outside of a script block. Use the warnError or catchError step instead of unstable , as in the first example here : stage ( 'Tests: EN' ){ steps{ warnError( 'Tests failed!' ) { sh 'HOME=$(pwd) bundle && HOME=$(pwd) LOCALE=en BROWSER=chrome-headless-nogpu cucumber --format json --out reports/en.json' } } } I will try to update the blog post to explicitly mention that the try/catch example only applies for scripted Pipelines.
            Hide
            warden Radek Antoniuk added a comment -

            Devin Nusbaum any if I'm doing anything wrong in the Declarative definition?

            Show
            warden Radek Antoniuk added a comment - Devin Nusbaum any if I'm doing anything wrong in the Declarative definition?

              People

              • Assignee:
                Unassigned
                Reporter:
                warden Radek Antoniuk
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: