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

Workflow parse exception with new approach for unstable stages

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Not A Defect
    • pipeline
    • None
    • Jenkins 2.176.1

    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

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

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

            warden 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.

            dnusbaum Devin Nusbaum added a comment - warden 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.

            Got it, thanks!

            warden Radek Antoniuk added a comment - Got it, thanks!

            People

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

              Dates

                Created:
                Updated:
                Resolved: