public FormValidation doCheckStageName(@QueryParameter String value) { String s = Util.fixEmptyAndTrim(value); if (s == null || s.equals("")) { return FormValidation.error(Messages.RestartDeclarativePipelineAction_NullStageName()); } if (!getRestartableStages().contains(s)) { return FormValidation.error(Messages.RestartDeclarativePipelineAction_StageNameNotPresent(s, run.getFullDisplayName())); } return FormValidation.ok(); }
public Queue.Item run(String stageName) { if (stageName == null || stageName.equals("")) { throw new IllegalStateException(Messages.RestartDeclarativePipelineAction_NullStageName()); } if (!run.hasPermission(Item.BUILD) || !run.getParent().isBuildable()) { throw new IllegalStateException(Messages.RestartDeclarativePipelineAction_ProjectNotBuildable(run.getParent().getFullName())); } if (run.isBuilding()) { throw new IllegalStateException(Messages.RestartDeclarativePipelineAction_OriginRunIncomplete(run.getFullDisplayName())); } ExecutionModelAction execAction = run.getAction(ExecutionModelAction.class); if (execAction == null) { throw new IllegalStateException(Messages.RestartDeclarativePipelineAction_OriginWasNotDeclarative(run.getFullDisplayName())); } if (!getRestartableStages().contains(stageName)) { throw new IllegalStateException(Messages.RestartDeclarativePipelineAction_StageNameNotPresent(stageName, run.getFullDisplayName())); } List<Action> actions = new ArrayList<>(); CpsFlowExecution execution = getExecution(); if (execution == null) { throw new IllegalStateException(Messages.RestartDeclarativePipelineAction_OriginRunMissingExecution(run.getFullDisplayName())); } actions.add(new RestartFlowFactoryAction(run.getExternalizableId())); actions.add(new CauseAction(new Cause.UserIdCause(), new RestartDeclarativePipelineCause(run, stageName))); return ParameterizedJobMixIn.scheduleBuild2(run.getParent(), 0, actions.toArray(new Action[actions.size()])); }
@Override protected int run() throws Exception { Run<?,?> run = number <= 0 ? job.getLastBuild() : job.getBuildByNumber(number); if (run == null) { throw new AbortException("No such build"); } RestartDeclarativePipelineAction action = run.getAction(RestartDeclarativePipelineAction.class); if (action == null) { throw new AbortException("Not a Declarative Pipeline build"); } if (!action.isRestartEnabled()) { throw new AbortException("Not authorized to restart builds of this job"); } if (!action.getRestartableStages().contains(stage)) { throw new AbortException("Stage " + stage + " either does not exist in the build, or did not run in the build, and so cannot be restarted."); } action.run(stage); return 0; }
List<String> restartableStages = action.getRestartableStages(); assertThat(restartableStages, is(Arrays.asList("skip-on-restart", "restart")));
List<String> restartableStages = action.getRestartableStages(); assertThat(restartableStages, is(Arrays.asList("skip-on-restart", "restart")));