Jenkins Pipeline Execute a closure (like in "parallel" step)

Viewed 860

I have a very long and complex pipeline that I'm rewriting after a major jenkins upgrade.

What I'd like to to is declaring my stages as variables,then execute them in the main node body: I can do this easily for the parallel stages, but I want to have the same style also for the sequential ones.

After a lot of tests, the only way I found to make this work was using "fake" parallel calls around all single sequential stages (ugly), I'm sure there is a better solution but seems like I can't find the proper step...shame on me.

Here's my example:

stage1 = { stage("one") {
            println "stage one"
         } }

stage2 = { stage("two") {
            println "stage two"
         } }

stage3 = { stage("three") {
            println "stage three"
         } }

node {
    parallel (
        "one" : stage1 ,
        "two" : stage2
    )
    HERE I WANT TO CALL stage3 Closure, possibly giving a map like in the parallel above
}
1 Answers

You should be able to do this with the run method.

stage3.run()

I do not know if this is safe to use.

Related