use of org.jenkinsci.plugins.pubsub.Message 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", new ChannelSubscriber() {
@Override
public void onMessage(@Nonnull Message 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