I am creating a Jenkins plugin that adds a custom pipeline step.
I have successfully got Java code to execute when my step (dostuff
) is used in a pipeline script, such as
script1
node {
stage( 'doingstuff' ) {
dostuff()
}
}
However, I want my custom step to render some stages and parallel streams in the Jenkins WebUI visualization, so I want to be doing the equivalent of parallel([...])
and stage( ... ) { ... }
and maybe even node { ... }
blocks in my plugin. For example, if the following were my intended pipeline:
script2
node {
stage( 'one' ) {
parallel([
"stream one": {
sh "echo hi from stream one"
},
"stream two": {
sh "echo hi from stream two"
}
])
}
}
I would like to reduce it to
script3
node {
dostuff()
}
where dostuff()
will do the equivalent of
script4
stage( 'one' ) {
parallel([
"stream one": {
sh "echo hi from stream one"
},
"stream two": {
sh "echo hi from stream two"
}
])
}
and, importantly, will render properly in the "Pipeline Steps" view of the Jenkins WebUI, and so that the parallel streams will render properly in the Blue Ocean web UI.
While I have seen how to execute the body block that is passed to a custom step defined in a plugin, from a pipeline script (for example), I cannot figure out the idiom for creating a body block in Java code.
I do not want to/cannot do this in pure Groovy because
import
ed (though they could maybe be @Grab
'd))synchronized
, and as far as I can tell pipeline scripts do not support this.I spoke to Andrew Bayer - engineer working on pipeline for CloudBees - at Jenkins World 2017 and he confirmed that it's architecturally impossible to compose a pipeline step of other pipeline steps from pure Java in a Jenkins plug-in.