Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Declarative Pipeline Syntax Within Jenkins Templating Engine #403

Merged
merged 3 commits into from
Sep 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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