Java Code Examples for hudson.util.OneShotEvent#isSignaled()
The following examples show how to use
hudson.util.OneShotEvent#isSignaled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MergeRequestHookTriggerHandlerImplTest.java From gitlab-plugin with GNU General Public License v2.0 | 6 votes |
private boolean ciSkipTestHelper(String MRDescription, String lastCommitMsg) throws IOException, InterruptedException { final OneShotEvent buildTriggered = new OneShotEvent(); FreeStyleProject project = jenkins.createFreeStyleProject(); project.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { buildTriggered.signal(); return true; } }); project.setQuietPeriod(0); MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(Arrays.asList(State.opened, State.reopened), Arrays.asList(Action.approved), false, false, false); mergeRequestHookTriggerHandler.handle(project, mergeRequestHook() .withObjectAttributes(defaultMergeRequestObjectAttributes().withDescription(MRDescription).withLastCommit(commit().withMessage(lastCommitMsg).withAuthor(user().withName("test").build()).withId("testid").build()).build()) .build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)), newMergeRequestLabelFilter(null)); buildTriggered.block(10000); return buildTriggered.isSignaled(); }
Example 2
Source File: SseEventTest.java From blueocean-plugin with MIT License | 4 votes |
@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()); } }
Example 3
Source File: SseEventTest.java From blueocean-plugin with MIT License | 4 votes |
@Test public void multiBranchJobEventsWithCustomOrg() throws Exception { MockFolder folder = j.createFolder("TestOrgFolderName"); assertNotNull(folder); setupScm(); final OneShotEvent success = new OneShotEvent(); final Boolean[] pipelineNameMatched = {null}; final Boolean[] mbpPipelineNameMatched = {null}; 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))) { if ("org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject".equals(message.get(jenkins_object_type))) { if("pipeline1".equals(message.get(blueocean_job_pipeline_name))) { mbpPipelineNameMatched[0] = true; }else{ mbpPipelineNameMatched[0] = false; } } else if ("org.jenkinsci.plugins.workflow.job.WorkflowJob".equals(message.get(jenkins_object_type))) { if("pipeline1".equals(message.get(blueocean_job_pipeline_name))) { pipelineNameMatched[0] = true; }else { pipelineNameMatched[0] = false; } } } if(pipelineNameMatched[0] != null && mbpPipelineNameMatched[0] != null){ success.signal(); } } }); con.subscribe("pipeline"); con.subscribe("job"); final WorkflowMultiBranchProject mp = folder.createProject(WorkflowMultiBranchProject.class, "pipeline1"); mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0]))); for (SCMSource source : mp.getSCMSources()) { assertEquals(mp, source.getOwner()); } mp.scheduleBuild2(0).getFuture().get(); WorkflowJob p = mp.getItem("master"); if (p == null) { mp.getIndexing().writeWholeLogTo(System.out); fail("master project not found"); } j.waitUntilNoActivity(); WorkflowRun b1 = p.getLastBuild(); assertEquals(1, b1.getNumber()); assertEquals(2, mp.getItems().size()); success.block(5000); con.close(); if(success.isSignaled()) { assertTrue(pipelineNameMatched[0]); assertTrue(mbpPipelineNameMatched[0]); } }