Restart from stage

29 views
Skip to first unread message

unli...@gmail.com

unread,
Mar 22, 2021, 6:47:45 PM3/22/21
to Jenkins Users
Are there any examples of the implementation of running a pipeline from a particular stage? I need to set in the pipeline parameters to make it run on a specific node and from a specific stage. If there are no questions with the first one, what are the easiest options to pass <stage name> from which to run the pipelines, skipping the previous ones?
Something similar I found here but it's not enough for me to implement this task:
https://github.com/SAP/jenkins-library/blob/master/vars/pipelineRestartSteps.groovy

https://issues.jenkins.io/browse/JENKINS-52391

Thanks!

Gianluca Massera

unread,
Mar 22, 2021, 6:52:59 PM3/22/21
to jenkins...@googlegroups.com
Hi what-ever-is-your-name-:-)

I use the "when" block to run only specific stages depending on the
parameters: https://www.jenkins.io/doc/book/pipeline/syntax/#when

I hope that fits your case too.

Cheers,

Gianluca.

unli...@gmail.com

unread,
Mar 22, 2021, 8:22:35 PM3/22/21
to Gianluca Massera
Thanks, Gianluca.

Your professional help, as always, is very operational and useful!
Thanks to you, I have implemented the ability to run from any Stage, but I would also like to form in "Active Choices Reactive Parameter" plugin automatic list from the names of Stages {}, which I have in PiPleine. Are there ready examples of code to obtain a list of names of all Stages from code pipeline (to select the stage I need before building the pipeline) ?

Gianluca Massera

unread,
Mar 23, 2021, 3:50:30 AM3/23/21
to jenkins...@googlegroups.com
Hi,

I use the following code to walk through all stages of the pipeline for
a different reason but it could be an hint for you to achieve your goal:

WorkflowRun run = prevBuild.getRawBuild()
NodeGraphBuilder graphBuilder =
NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(run);
 def flowNodes = graphBuilder.getPipelineNodes()

 for (Iterator iterator = flowNodes.iterator(); iterator.hasNext();) {
        def node = iterator.next()
        if (node.getDisplayName() == stageName) {
            return node.getStatus().getResult() == BlueRunResult.SUCCESS
        }
 }

A stage is a pipeline node, but there are nodes that are not stages. So,
you probably need to dig into internal code to find out how to identify
only the stages.

Cheers,

Gianluca.
Reply all
Reply to author
Forward
0 new messages