use of org.jenkinsci.plugins.workflow.support.steps.input.InputStep in project blueocean-plugin by jenkinsci.
the class PipelineStepVisitor method atomNode.
@Override
public void atomNode(@CheckForNull FlowNode before, @Nonnull FlowNode atomNode, @CheckForNull FlowNode after, @Nonnull ForkScanner scan) {
if (stageStepsCollectionCompleted && !PipelineNodeUtil.isSyntheticStage(currentStage)) {
return;
}
if (atomNode instanceof StepEndNode) {
this.closestEndNode = (StepEndNode) atomNode;
}
if (atomNode instanceof StepAtomNode && !PipelineNodeUtil.isSkippedStage(currentStage)) {
// if skipped stage, we don't collect its steps
long pause = PauseAction.getPauseDuration(atomNode);
chunk.setPauseTimeMillis(chunk.getPauseTimeMillis() + pause);
TimingInfo times = StatusAndTiming.computeChunkTiming(run, pause, atomNode, atomNode, after);
if (times == null) {
times = new TimingInfo();
}
NodeRunStatus status;
InputStep inputStep = null;
if (PipelineNodeUtil.isPausedForInputStep((StepAtomNode) atomNode, inputAction)) {
status = new NodeRunStatus(BlueRun.BlueRunResult.UNKNOWN, BlueRun.BlueRunState.PAUSED);
try {
for (InputStepExecution execution : inputAction.getExecutions()) {
FlowNode node = execution.getContext().get(FlowNode.class);
if (node != null && node.equals(atomNode)) {
inputStep = execution.getInput();
break;
}
}
} catch (IOException | InterruptedException | TimeoutException e) {
logger.error("Error getting FlowNode from execution context: " + e.getMessage(), e);
}
} else {
status = new NodeRunStatus(atomNode);
}
FlowNodeWrapper node = new FlowNodeWrapper(atomNode, status, times, inputStep, run);
if (PipelineNodeUtil.isPreSyntheticStage(currentStage)) {
preSteps.push(node);
} else if (PipelineNodeUtil.isPostSyntheticStage(currentStage)) {
postSteps.push(node);
} else {
if (!steps.contains(node)) {
steps.push(node);
}
}
stepMap.put(node.getId(), node);
// but only if the previous node did not fail
if (closestEndNode != null && closestEndNode.getError() != null && new NodeRunStatus(before).result != BlueRunResult.FAILURE) {
node.setBlockErrorAction(closestEndNode.getError());
// prepare for next block
closestEndNode = null;
}
}
}
use of org.jenkinsci.plugins.workflow.support.steps.input.InputStep in project blueocean-plugin by jenkinsci.
the class PipelineStepImpl method parseValue.
private Object parseValue(InputStepExecution execution, JSONArray parameters, StaplerRequest request) throws IOException, InterruptedException {
Map<String, Object> mapResult = new HashMap<>();
InputStep input = execution.getInput();
for (Object o : parameters) {
JSONObject p = (JSONObject) o;
String name = (String) p.get(NAME_ELEMENT);
if (name == null) {
throw new ServiceException.BadRequestException("name is required parameter element");
}
ParameterDefinition d = null;
for (ParameterDefinition def : input.getParameters()) {
if (def.getName().equals(name))
d = def;
}
if (d == null)
throw new ServiceException.BadRequestException("No such parameter definition: " + name);
ParameterValue v = d.createValue(request, p);
if (v == null) {
continue;
}
mapResult.put(name, convert(name, v));
}
// If a destination value is specified, push the submitter to it.
String valueName = input.getSubmitterParameter();
if (valueName != null && !valueName.isEmpty()) {
Authentication a = Jenkins.getAuthentication2();
mapResult.put(valueName, a.getName());
}
switch(mapResult.size()) {
case 0:
// no value if there's no parameter
return null;
case 1:
return mapResult.values().iterator().next();
default:
return mapResult;
}
}
use of org.jenkinsci.plugins.workflow.support.steps.input.InputStep in project blueocean-plugin by jenkinsci.
the class SseEventTest method pipelineWithInput.
@Test
public void pipelineWithInput() throws IOException, ExecutionException, InterruptedException, TimeoutException {
final OneShotEvent success = new OneShotEvent();
String script = "node {\n" + " stage(\"build\"){\n" + " echo \"running\"\n" + " input message: 'Please input branch to test against', parameters: [[$class: 'StringParameterDefinition', defaultValue: 'master', description: '', name: 'branch']]\n" + " }\n" + "}";
final boolean[] wasPaused = { false };
final boolean[] wasUnPaused = { false };
final AssertionHelper assertionHelper = new AssertionHelper();
SSEConnection con = new SSEConnection(j.getURL(), "me", message -> {
System.out.println(message);
if ("job".equals(message.get(jenkins_channel))) {
assertionHelper.isEquals("/blue/rest/organizations/jenkins/pipelines/pipeline1/", message.get(blueocean_job_rest_url));
assertionHelper.isEquals("pipeline1", message.get(blueocean_job_pipeline_name));
if (message.get(jenkins_event).equals(Events.JobChannel.job_run_queue_left.name())) {
assertionHelper.isEquals("1", message.get(blueocean_queue_item_expected_build_number));
assertionHelper.isNotNull(message.get(Job.job_run_queueId));
assertionHelper.isNotNull(message.get(Job.job_run_status));
}
assertionHelper.isEquals("pipeline1", message.get(job_name));
assertionHelper.isEquals("job", message.get(jenkins_channel));
assertionHelper.isEquals("jenkins", message.get(jenkins_org));
assertionHelper.isNull(message.get(job_ismultibranch));
assertionHelper.isNull(message.get(job_multibranch_indexing_result));
assertionHelper.isNull(message.get(job_multibranch_indexing_status));
if ("job_run_unpaused".equals(message.get(jenkins_event))) {
wasUnPaused[0] = true;
}
} else if ("pipeline".equals(message.get(jenkins_channel))) {
assertionHelper.isEquals("1", message.get(pipeline_run_id));
if (message.get(jenkins_event).equals(pipeline_stage.name())) {
assertionHelper.isEquals("build", message.get(pipeline_step_stage_name));
}
if ("input".equals(message.get(pipeline_step_name))) {
wasPaused[0] = true;
assertionHelper.isEquals("true", message.get(pipeline_step_is_paused));
}
}
if (wasPaused[0] && wasUnPaused[0]) {
// signal finish only when both conditions are met
success.signal();
}
});
con.subscribe("pipeline");
con.subscribe("job");
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(script, false));
QueueTaskFuture<WorkflowRun> buildTask = job1.scheduleBuild2(0);
WorkflowRun run = buildTask.getStartCondition().get();
CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
while (run.getAction(InputAction.class) == null) {
e.waitForSuspension();
}
// Now that flow is paused, send a signal that it's un-paused
ExtensionList<PipelineEventListener.InputStepPublisher> inputStepPublisherList = ExtensionList.lookup(PipelineEventListener.InputStepPublisher.class);
assertFalse(inputStepPublisherList.isEmpty());
InputAction inputAction = run.getAction(InputAction.class);
List<InputStepExecution> executionList = inputAction.getExecutions();
assertFalse(executionList.isEmpty());
InputStep inputStep = executionList.get(0).getInput();
inputStepPublisherList.get(0).onStepContinue(inputStep, run);
success.block(5000);
con.close();
if (success.isSignaled()) {
assertTrue(wasPaused[0]);
assertTrue(wasUnPaused[0]);
}
if (assertionHelper.totalErrors() > 0) {
fail("There were errors: " + assertionHelper.totalErrors());
}
}
Aggregations