Reputation: 2168
I know that in a scripted jenkins pipeline I can use Utils.markStageSkippedForConditional
to mark an entire stage as skipped, which gets the 'execution line' to dip around the stage in the Blue Ocean UI.
But if I've got a stage that has parallel tasks under it, something like this:
stage('Stage 1') {
parallel 'Task 1' : {
node('requirements') {
doTask1()
}
}, 'Task 2' : {
when (mustDoTask2) { // this 'when' function calls Utils.markStageSkippedForConditional
node('requirements') {
doTask2()
}
}
}
}
Then the entire stage is marked as skipped (unsurprisingly I suppose given the Utils function name) and Blue Ocean renders the pipeline as never executing any of the parallel tasks (even though they do execute).
So is there an alternative to Utils.markStageSkippedForConditional
that I can use to just mark an individual parallel task as skipped?
The alternative I've got at the moment is for the parallel tasks to check within the 'node' statement as to whether they should execute anything, which works but when you look at the pipeline in Blue Ocean it looks like those tasks are always executed, which isn't ideal.
Upvotes: 3
Views: 2661
Reputation: 2168
@PatriceM. suggested putting each task into its own stage, which is the best solution I've got at the moment:
stage('Stage 1') {
parallel 'Task 1' : {
node('requirements') {
doTask1()
}
}, 'Task 2' : {
stage('Task 2') { // new nested stage that can be marked as skipped by the 'when'
when (mustDoTask2) {
node('requirements') {
doTask2()
}
}
}
}
}
Note that the 'Task 2' parallel task has its own stage. This means the 'when' can mark that stage as skipped, rather than the parent stage 'Stage 1'. It's not necessary to add the extra nested stage to 'Task 1' as it doesn't have a 'when' to potentially skip it.
This results in Blue Ocean showing the skipped stages in grey (not with the line dipping around them) and has the log 'queued waiting for run to start' until the entire run has finished when it will change to 'this stage has no steps' and shows the final logs of the entire run. It's not 100% perfect but shows what's actually happened fairly well so good enough for now!
Upvotes: 2