diff --git a/pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy b/pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy index af20d8b15..3faffc485 100644 --- a/pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy +++ b/pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy @@ -37,6 +37,7 @@ import org.codehaus.groovy.ast.expr.* import org.codehaus.groovy.ast.stmt.BlockStatement import org.codehaus.groovy.ast.stmt.ExpressionStatement import org.codehaus.groovy.ast.stmt.Statement +import org.codehaus.groovy.ast.stmt.TryCatchStatement import org.codehaus.groovy.classgen.VariableScopeVisitor import org.codehaus.groovy.control.SourceUnit import org.codehaus.groovy.syntax.Types @@ -174,6 +175,30 @@ class ModelParser implements Parser { return pipelineDefs.get(0) } } + + /* + * If this is the Jenkins Templating Engine, the structure will be: + * try{ + * .. + * <-- might be pipeline block + * } catch { + * .. + * } + */ + if(!src.statementBlock.statements.isEmpty()){ + def firstStatement = src.statementBlock.statements.get(0) + if (firstStatement instanceof BlockStatement) { + def maybeTry = firstStatement.getStatements().last() + if (maybeTry instanceof TryCatchStatement){ + def pipelineStatement = maybeTry.getTryStatement().statements.find{ stmt -> + return isDeclarativePipelineStep(stmt) + } + if (pipelineStatement != null){ + return parsePipelineStep(src, pipelineStatement, secondaryRun) + } + } + } + } } // Check if there's a 'pipeline' step somewhere nested within the other statements and error out if that's the case.