Skip to content

Commit

Permalink
add JTE to ModelParser
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-terrana committed Aug 23, 2020
1 parent d05e558 commit c5bebf4
Showing 1 changed file with 23 additions and 0 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -174,6 +175,28 @@ class ModelParser implements Parser {
return pipelineDefs.get(0)
}
}

/*
* If this is the Jenkins Templating Engine, the structure will be:
* try{
* ..
* <user defined template> <-- might be pipeline block
* } catch {
* ..
* }
*/
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.
Expand Down

0 comments on commit c5bebf4

Please sign in to comment.