How to repeat a stage in Jenkins Workflow
This is only possible in the enterprise version of Jenkins. As @jesse-glick pointed out, you have the Checkpoint Plugin available there, see the documentation.
There's is currently no plan to support this feature in the OSS-version according to CloudBees. See this issue: JENKINS-33846
Supposing it is the last (Ansible) stage you want to be able to restart from, you could place a checkpoint
just before it.
checkpoint 'about to deploy'stage 'DevOps - Ansible'input message: 'Release to Production', ok: 'Release'node { // TODO}
If you want to deploy to a selectable target, you could use input
:
checkpoint 'about to deploy'stage 'DevOps - Ansible'def target = input message: 'Where to release?', parameters: [[$class: 'StringParameterDefinition', name: 'target']]node { // TODO}
The more complicated scenario is that you want to always deploy to a standard target the first time around, but when resuming from a checkpoint you want to ask the user for an alternate target. For that you need to know when you are resuming. Currently checkpoint
does not offer this information directly (CJP-1620 in the CloudBees internal issue tracker), but there is a workaround:
def origBuildNumber = env.BUILD_NUMBERcheckpoint 'about to deploy'stage 'DevOps - Ansible'def targetif (origBuildNumber == env.BUILD_NUMBER) { // original target = 'production'} else { // resumed target = input message: 'Where to release?', parameters: [[$class: 'StringParameterDefinition', name: 'target']]}node { // TODO}