I have the following build pipeline set up as a job:
Stage 1 - verify all dependencies exist
Stage 2 - build the new jar
Stage 3 - Run integration tests
Stage 4 - Deploy to staging environment (manual step)
Stage 5 - Deploy to production environment (manual step)
I am looking for a way to start the build pipeline from a particular stage in case of a transient failure. For example, let's say there was a network issue when the user clicked to deploy to production. I don't think it makes sense to start the pipeline from stage 1... I'd like to try that step again and continue on from there in the pipeline. I don't see any functionality like this in the Build Pipeline Plugin.
Thanks!!
I think
checkpoint
is what you are looking for. Unfortunately it is only available in the CloudBees Jenkins Enterprise suite, not in the free version.Let's hope it makes it into the open-source version as it seems to be a very common use case.
You can wrap your code in a
retry
step:EDIT: This might help in the free version of Jenkins. Users of CloudBees Enterprise, please see @tarantoga's answer.
Here's another sketch to run stages conditionally without breaking the Stage View Plugin history.
As they say:
Here's what I've come up with so far. Seems to work mostly: (Just ignore the other dummy steps)
We define a little
conditionalStage
helper function that neatly wraps up the stage name checking from theJP_STAGE
Jenkins Job parameter.Notice how
conditionalStage
first opens thestage
and then checksstageIsActive
within the stage, just skipping all steps. This way, the Stage View Plugin sees all stages and soesn't mess up, but the stages' steps are still skipped.What you could do is to put the single steps into groovy scripts. Then you can make a "runAll"-job that loads all of the scripts in the correct order, and single jobs for the different steps.
Although this is a way that should work, I do not think that this is the ideal solution, as it means that you have to take care how the different steps exchange information, so that the steps can run independently.
A built-in solution would be much better.
A bit old topic but since Jenkins still (!) doesn't support this I'm sending another solution for scripted pipeline implementations. It's based on building stages list dynamically when running pipeline.
def stages = prepareStages(Steps.getByName("${startStage}"))
the "startStage" is a build parameter defined as follows
parameters { choiceParam('startStage', [ 'prepare', 'build', 'analyse', 'checkQG', 'provision', 'deploy', 'activate', 'verify', 'cleanup' ], 'Pick up the stage you want to start from') }
This allows me to pick up the stage I want to start the pipeline from (prepare stage is set by default)
Meanwhile, all of the other answers are obsolete, as Jenkins provides a built-in solution that allows you to restart a job from any stage: https://jenkins.io/doc/book/pipeline/running-pipelines/