@Exported public boolean isRestartEnabled() { ExecutionModelAction executionModelAction = run.getAction(ExecutionModelAction.class); return executionModelAction != null && !run.isBuilding() && run.hasPermission(Item.BUILD) && run.getParent().isBuildable() && getExecution() != null; }
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()])); }
@Exported public List<String> getRestartableStages() { List<String> stages = new ArrayList<>(); FlowExecution execution = getExecution(); if (execution != null) { ExecutionModelAction execAction = run.getAction(ExecutionModelAction.class); if (execAction != null) { if (execAction.getStages() != null) { for (ModelASTStage s : execAction.getStages().getStages()) { if (!Utils.stageHasStatusOf(s.getName(), execution, StageStatus.getSkippedForFailure(), StageStatus.getSkippedForUnstable())) { stages.add(s.getName()); } } } } } return stages; }