Skip to content

Commit

Permalink
Merge pull request #403 from steven-terrana/integrate-jte
Browse files Browse the repository at this point in the history
Support Declarative Pipeline Syntax Within Jenkins Templating Engine
  • Loading branch information
bitwiseman authored Sep 23, 2020
2 parents 05e4609 + b925342 commit 9f23d5e
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
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,30 @@ 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 {
* ..
* }
*/
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.
Expand Down

0 comments on commit 9f23d5e

Please sign in to comment.