org.jenkinsci.plugins.workflow.cps.CpsFlowExecution Java Examples
The following examples show how to use
org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.
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: GithubBuildStatusGraphListenerTest.java From github-autostatus-plugin with MIT License | 6 votes |
@Test public void testAtomNode() throws IOException { ErrorAction error = mock(ErrorAction.class); CpsFlowExecution execution = mock(CpsFlowExecution.class); StepAtomNode stageNode = new StepAtomNode(execution, null, mock(FlowNode.class)); stageNode.addAction(error); FlowExecutionOwner owner = mock(FlowExecutionOwner.class); when(execution.getOwner()).thenReturn(owner); Executable exec = mock(Executable.class); when(owner.getExecutable()).thenReturn(exec); AbstractBuild build = mock(AbstractBuild.class); when(owner.getExecutable()).thenReturn(build); when(build.getAction(ExecutionModelAction.class)).thenReturn(null); // not declarative BuildStatusAction buildStatusAction = mock(BuildStatusAction.class); when(build.getAction(BuildStatusAction.class)).thenReturn(buildStatusAction); GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener(); instance.onNewHead(stageNode); verify(buildStatusAction).sendNonStageError(any()); }
Example #2
Source File: DeclarativeDockerUtils.java From docker-workflow-plugin with MIT License | 6 votes |
private static Run<?,?> currentRun() { try { CpsThread t = CpsThread.current(); if (t != null) { CpsFlowExecution e = t.getExecution(); if (e != null) { FlowExecutionOwner o = e.getOwner(); if (o != null && o.getExecutable() instanceof Run) { return (Run)o.getExecutable(); } } } return null; } catch (IOException i) { return null; } }
Example #3
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 6 votes |
@Issue("JENKINS-47158") @Test public void syntheticParallelFlowNodeNotSaved() throws Exception { WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "pipeline1"); p.setDefinition(new CpsFlowDefinition("parallel a: {\n" + " node {\n" + " echo 'a'\n" + " }\n" + "}, b: {\n" + " node {\n" + " echo 'b'\n" + " }\n" + "}\n", true)); WorkflowRun b = j.buildAndAssertSuccess(p); get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class); FlowExecution rawExec = b.getExecution(); assert (rawExec instanceof CpsFlowExecution); CpsFlowExecution execution = (CpsFlowExecution) rawExec; File storage = execution.getStorageDir(); // Nodes 5 and 6 are the parallel branch start nodes. Make sure no "5-parallel-synthetic.xml" and "6..." files // exist in the storage directory, showing we haven't saved them. assertFalse(new File(storage, "5-parallel-synthetic.xml").exists()); assertFalse(new File(storage, "6-parallel-synthetic.xml").exists()); }
Example #4
Source File: GithubBuildStatusGraphListenerTest.java From github-autostatus-plugin with MIT License | 6 votes |
/** * Verifies onNewHead adds the build action for an atom node if there's an error (used for sending errors that occur * out of a stage */ @Test public void testAtomNodeAddsAction() throws IOException { ErrorAction error = mock(ErrorAction.class); CpsFlowExecution execution = mock(CpsFlowExecution.class); StepAtomNode stageNode = new StepAtomNode(execution, null, mock(FlowNode.class)); stageNode.addAction(error); FlowExecutionOwner owner = mock(FlowExecutionOwner.class); when(execution.getOwner()).thenReturn(owner); AbstractBuild build = mock(AbstractBuild.class); when(owner.getExecutable()).thenReturn(build); when(build.getAction(ExecutionModelAction.class)).thenReturn(null); // not declarative GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener(); instance.onNewHead(stageNode); verify(build).addAction(any(BuildStatusAction.class)); }
Example #5
Source File: GithubBuildStatusGraphListenerTest.java From github-autostatus-plugin with MIT License | 5 votes |
@Test public void testBuildStateForStageWithError() throws IOException { CpsFlowExecution execution = mock(CpsFlowExecution.class); StepStartNode stageStartNode = mock(StepStartNode.class); ErrorAction error = mock(ErrorAction.class); StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, mock(FlowNode.class)); stageEndNode.addAction(error); GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener(); BuildStage.State state = instance.buildStateForStage(stageStartNode, stageEndNode); assertEquals(BuildStage.State.CompletedError, state); }
Example #6
Source File: GithubBuildStatusGraphListenerTest.java From github-autostatus-plugin with MIT License | 5 votes |
@Test public void buildStateForStageSuccess() { CpsFlowExecution execution = mock(CpsFlowExecution.class); when(execution.iotaStr()).thenReturn("1", "2", "3", "4"); FlowStartNode parentNode = new FlowStartNode(execution, "5"); StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode); StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode); BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode); assertEquals(BuildStage.State.CompletedSuccess, result); }
Example #7
Source File: GithubBuildStatusGraphListenerTest.java From github-autostatus-plugin with MIT License | 5 votes |
@Test public void buildStateForStageError() { CpsFlowExecution execution = mock(CpsFlowExecution.class); when(execution.iotaStr()).thenReturn("1", "2", "3", "4"); FlowStartNode parentNode = new FlowStartNode(execution, "5"); StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode); StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode); ErrorAction errorAction = mock(ErrorAction.class); stageEndNode.addAction(errorAction); BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode); assertEquals(BuildStage.State.CompletedError, result); }
Example #8
Source File: GithubBuildStatusGraphListenerTest.java From github-autostatus-plugin with MIT License | 5 votes |
@Test public void buildStateForStageSkippedUnstable() { CpsFlowExecution execution = mock(CpsFlowExecution.class); when(execution.iotaStr()).thenReturn("1", "2", "3", "4"); FlowStartNode parentNode = new FlowStartNode(execution, "5"); StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode); StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode); TagsAction tagsAction = mock(TagsAction.class); when(tagsAction.getTagValue(StageStatus.TAG_NAME)).thenReturn(StageStatus.getSkippedForUnstable()); stageEndNode.addAction(tagsAction); BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode); assertEquals(BuildStage.State.SkippedUnstable, result); }
Example #9
Source File: GithubBuildStatusGraphListenerTest.java From github-autostatus-plugin with MIT License | 5 votes |
@Test public void buildStateForStageSkippedConditional() { CpsFlowExecution execution = mock(CpsFlowExecution.class); when(execution.iotaStr()).thenReturn("1", "2", "3", "4"); FlowStartNode parentNode = new FlowStartNode(execution, "5"); StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode); StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode); TagsAction tagsAction = mock(TagsAction.class); when(tagsAction.getTagValue(StageStatus.TAG_NAME)).thenReturn(StageStatus.getSkippedForConditional()); stageEndNode.addAction(tagsAction); BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode); assertEquals(BuildStage.State.SkippedConditional, result); }
Example #10
Source File: GithubBuildStatusGraphListenerTest.java From github-autostatus-plugin with MIT License | 5 votes |
@Test public void buildStateForStageFailedAndContinued() { CpsFlowExecution execution = mock(CpsFlowExecution.class); when(execution.iotaStr()).thenReturn("1", "2", "3", "4"); FlowStartNode parentNode = new FlowStartNode(execution, "5"); StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode); StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode); TagsAction tagsAction = mock(TagsAction.class); when(tagsAction.getTagValue(StageStatus.TAG_NAME)).thenReturn(StageStatus.getFailedAndContinued()); stageEndNode.addAction(tagsAction); BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode); assertEquals(BuildStage.State.CompletedError, result); }
Example #11
Source File: GithubBuildStatusGraphListenerTest.java From github-autostatus-plugin with MIT License | 5 votes |
@Test public void testBuildStateForStageWithTag() throws IOException { CpsFlowExecution execution = mock(CpsFlowExecution.class); StepStartNode stageStartNode = mock (StepStartNode.class); StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, mock(FlowNode.class)); TagsAction tag = mock(TagsAction.class); stageEndNode.addAction(tag); when(tag.getTagValue(StageStatus.TAG_NAME)).thenReturn("SKIPPED_FOR_FAILURE"); GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener(); BuildStage.State state = instance.buildStateForStage(stageStartNode, stageEndNode); assertEquals(BuildStage.State.SkippedFailure, state); }
Example #12
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 5 votes |
@Test @Issue("JENKINS-49297") public void submitInputPostBlock() throws Exception { WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "pipeline1"); URL resource = Resources.getResource(getClass(), "stepsFromPost.jenkinsfile"); String jenkinsFile = Resources.toString(resource, Charsets.UTF_8); job.setDefinition(new CpsFlowDefinition(jenkinsFile, true)); QueueTaskFuture<WorkflowRun> buildTask = job.scheduleBuild2(0); WorkflowRun run = buildTask.getStartCondition().get(); CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get(); while (run.getAction(InputAction.class) == null) { e.waitForSuspension(); } List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class); assertEquals(1, nodes.size()); List<Map> steps = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + nodes.get(0).get("id") + "/steps/", List.class); assertEquals(3, steps.size()); assertEquals("7", steps.get(0).get("id")); assertEquals("Hello World", steps.get(0).get("displayDescription")); assertEquals("12", steps.get(1).get("id")); assertEquals("Hello World from post", steps.get(1).get("displayDescription")); assertEquals("13", steps.get(2).get("id")); assertEquals("Wait for interactive input", steps.get(2).get("displayName")); }
Example #13
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 5 votes |
@Test @Issue("JENKINS-48884") public void submitInputPostBlockWithParallelStages() throws Exception { WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "pipeline1"); URL resource = Resources.getResource(getClass(), "parallelStepsFromPost.jenkinsfile"); String jenkinsFile = Resources.toString(resource, Charsets.UTF_8); job.setDefinition(new CpsFlowDefinition(jenkinsFile, true)); QueueTaskFuture<WorkflowRun> buildTask = job.scheduleBuild2(0); WorkflowRun run = buildTask.getStartCondition().get(); CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get(); while (run.getAction(InputAction.class) == null) { e.waitForSuspension(); } List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class); assertEquals(6, nodes.size()); List<Map> steps = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + nodes.get(0).get("id") + "/steps/", List.class); assertEquals(4, steps.size()); assertEquals("15", steps.get(0).get("id")); assertEquals("exit 1", steps.get(0).get("displayDescription")); assertEquals("17", steps.get(1).get("id")); assertEquals("hello stable", steps.get(1).get("displayDescription")); assertEquals("47", steps.get(2).get("id")); assertEquals("Hello World from post", steps.get(2).get("displayDescription")); assertEquals("48", steps.get(3).get("id")); assertEquals("Wait for interactive input", steps.get(3).get("displayName")); }
Example #14
Source File: YamlFlowDefinition.java From simple-pull-request-job-plugin with Apache License 2.0 | 4 votes |
@Override public FlowExecution create(FlowExecutionOwner owner, TaskListener listener, List<? extends Action> actions) throws Exception { Queue.Executable exec = owner.getExecutable(); if (!(exec instanceof WorkflowRun)) { throw new IllegalStateException("inappropriate context"); } WorkflowRun build = (WorkflowRun) exec; WorkflowJob job = build.getParent(); BranchJobProperty property = job.getProperty(BranchJobProperty.class); Branch branch = property.getBranch(); ItemGroup<?> parent = job.getParent(); if (!(parent instanceof WorkflowMultiBranchProject)) { throw new IllegalStateException("inappropriate context"); } SCMSource scmSource = ((WorkflowMultiBranchProject) parent).getSCMSource(branch.getSourceId()); if (scmSource == null) { throw new IllegalStateException(branch.getSourceId() + " not found"); } GitConfig gitConfig = new GitConfig(); SCMHead head = branch.getHead(); if ("Pull Request".equals(head.getPronoun())) { ChangeRequestSCMHead2 changeRequestSCMHead2 = (ChangeRequestSCMHead2) branch.getHead(); head = changeRequestSCMHead2.getTarget(); } SCMRevision tip = scmSource.fetch(head, listener); if (tip == null) { throw new IllegalStateException("Cannot determine the revision."); } SCMRevision rev = scmSource.getTrustedRevision(tip, listener); GitSCM gitSCM = (GitSCM) scmSource.build(head, rev); gitConfig.setGitUrl(gitSCM.getUserRemoteConfigs().get(0).getUrl()); gitConfig.setCredentialsId(gitSCM.getUserRemoteConfigs().get(0).getCredentialsId()); gitConfig.setGitBranch(head.getName()); String script; try (SCMFileSystem fs = SCMFileSystem.of(scmSource, head, rev)) { if (fs != null) { InputStream yamlInputStream = fs.child(scriptPath).content(); listener.getLogger().println("Path of yaml/yml config file: " + fs.child(scriptPath).getPath()); YamlToPipeline y = new YamlToPipeline(); script = y.generatePipeline(yamlInputStream, gitConfig, listener); } else { throw new IOException("SCM not supported"); // FIXME implement full checkout } } listener.getLogger().println(script); return new CpsFlowExecution(script, false, owner); }
Example #15
Source File: ReadCSVStep.java From pipeline-utility-steps-plugin with MIT License | 4 votes |
@Override public void customizeImports(CpsFlowExecution context, ImportCustomizer ic) { ic.addStarImports(ORG_APACHE_COMMONS_CSV); }
Example #16
Source File: ReadMavenPomStep.java From pipeline-utility-steps-plugin with MIT License | 4 votes |
@Override public void customizeImports(CpsFlowExecution context, ImportCustomizer ic) { ic.addStarImports(ORG_APACHE_MAVEN_MODEL); }
Example #17
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 #18
Source File: GithubBuildStatusGraphListenerTest.java From github-autostatus-plugin with MIT License | 4 votes |
@Test public void testStepEndNode() throws Exception { long time = 12345L; // Mocked objects CpsFlowExecution execution = mock(CpsFlowExecution.class); StepStartNode stageStartNode = mock(StepStartNode.class); StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, mock(FlowNode.class)); ErrorAction error = mock(ErrorAction.class); stageEndNode.addAction(error); TimingAction startTime = mock(TimingAction.class); TimingAction endTime = mock(TimingAction.class); stageEndNode.addAction(endTime); when(startTime.getStartTime()).thenReturn(0L); when(endTime.getStartTime()).thenReturn(time); BuildStatusAction buildStatus = mock(BuildStatusAction.class); FlowExecutionOwner owner = mock(FlowExecutionOwner.class); AbstractBuild build = mock(AbstractBuild.class); // get BuildStatusAction from StepEndNode when(execution.getOwner()).thenReturn(owner); when(owner.getExecutable()).thenReturn(build); when(build.getAction(BuildStatusAction.class)).thenReturn(buildStatus); // get StepStartNode from StepEndNode String startId = "15"; when(stageStartNode.getId()).thenReturn(startId); when(execution.getNode(startId)).thenReturn(stageStartNode); // get time from StepStartNode to StepEndNode when(stageStartNode.getAction(TimingAction.class)).thenReturn(startTime); LabelAction labelAction = new LabelAction("some label"); when(stageStartNode.getAction(LabelAction.class)).thenReturn(labelAction); when(stageStartNode.getAction(StageAction.class)).thenReturn(mock(StageAction.class)); GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener(); instance.onNewHead(stageEndNode); verify(buildStatus).updateBuildStatusForStage(eq("some label"), eq(BuildStage.State.CompletedError), eq(time)); }
Example #19
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 4 votes |
@Test public void abortInput() throws Exception { String script = "node {\n" + " stage(\"thing\"){\n" + " input 'continue'\n" + " }\n" + "}"; 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(); } List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class); System.out.println(stepsResp); Assert.assertEquals("PAUSED", stepsResp.get(0).get("state")); Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result")); String stepId = (String) stepsResp.get(0).get("id"); //Assert.assertEquals("7", stepsResp.get(0).get("id")); Map<String, Object> input = (Map<String, Object>) stepsResp.get(0).get("input"); Assert.assertNotNull(input); String id = (String) input.get("id"); Assert.assertNotNull(id); JSONObject req = new JSONObject(); req.put("id", id); req.put("abort", true); post("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/" + stepId + "/", req, 200); if (waitForBuildCount(job1, 1, Result.ABORTED)) { Map<String, Object> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/" + stepId + "/"); Assert.assertEquals("FINISHED", resp.get("state")); Assert.assertEquals("ABORTED", resp.get("result")); Assert.assertEquals(stepId, resp.get("id")); } }
Example #20
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 4 votes |
@Test public void submitInput() throws Exception { String script = "node {\n" + " stage(\"first\"){\n" + " def branchInput = input message: 'Please input branch to test against', parameters: [[$class: 'StringParameterDefinition', defaultValue: 'master', description: '', name: 'branch']]\n" + " echo \"BRANCH NAME: ${branchInput}\"\n" + " }\n" + "}"; 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(); } List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class); Assert.assertEquals("PAUSED", stepsResp.get(0).get("state")); Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result")); Assert.assertEquals("7", stepsResp.get(0).get("id")); Map<String, Object> input = (Map<String, Object>) stepsResp.get(0).get("input"); Assert.assertNotNull(input); String id = (String) input.get("id"); Assert.assertNotNull(id); List<Map<String, Object>> params = (List<Map<String, Object>>) input.get("parameters"); post("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/7/", ImmutableMap.of("id", id, PARAMETERS_ELEMENT, ImmutableList.of(ImmutableMap.of("name", params.get(0).get("name"), "value", "master")) ) , 200); if (waitForBuildCount(job1, 1, Result.SUCCESS)) { Map<String, Object> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/7/"); Assert.assertEquals("FINISHED", resp.get("state")); Assert.assertEquals("SUCCESS", resp.get("result")); Assert.assertEquals("7", resp.get("id")); } }
Example #21
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 4 votes |
@Test public void testBlockedStep() throws Exception { String script = "node {\n" + " stage(\"one\"){\n" + " echo '1'\n" + " }\n" + " stage(\"two\") {\n" + " node('blah'){\n" + " sh 'blah'\n" + " }\n" + " }\n" + "\n" + "}"; WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1"); job1.setDefinition(new CpsFlowDefinition(script, false)); QueueTaskFuture<WorkflowRun> runQueueTaskFuture = job1.scheduleBuild2(0); WorkflowRun run = runQueueTaskFuture.getStartCondition().get(); CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get(); if (waitForItemToAppearInQueue(1000 * 300)) { //5 min timeout List<FlowNode> nodes = getStages(NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(run)); if (nodes.size() == 2) { List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/11/steps/", List.class); assertEquals(1, stepsResp.size()); assertEquals("QUEUED", stepsResp.get(0).get("state")); } } else { // Avoid spurious code coverage failures final FlowNode node = new FlowNode(null, "fake") { @Override protected String getTypeDisplayName() { return "fake"; } }; final MemoryFlowChunk chunk = new MemoryFlowChunk() { @Override public FlowNode getFirstNode() { return node; } }; new PipelineStepVisitor.LocalAtomNode(chunk, "fake"); } }
Example #22
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 4 votes |
@Test public void waitForInputTest() throws Exception { String script = "node {\n" + " stage(\"parallelStage\"){\n" + " parallel left : {\n" + " echo \"running\"\n" + " def branchInput = input message: 'Please input branch to test against', parameters: [[$class: 'StringParameterDefinition', defaultValue: 'master', description: '', name: 'branch']]\n" + " echo \"BRANCH NAME: ${branchInput}\"\n" + " }, \n" + " right : {\n" + " sh 'sleep 100000'\n" + " }\n" + " }\n" + "}"; 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(); } Map runResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/"); Assert.assertEquals("PAUSED", runResp.get("state")); List<FlowNodeWrapper> nodes = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(run).getPipelineNodes(); List<Map> nodesResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class); Assert.assertEquals("PAUSED", nodesResp.get(0).get("state")); Assert.assertEquals("UNKNOWN", nodesResp.get(0).get("result")); Assert.assertEquals("parallelStage", nodesResp.get(0).get("displayName")); Assert.assertEquals("PAUSED", nodesResp.get(1).get("state")); Assert.assertEquals("UNKNOWN", nodesResp.get(1).get("result")); Assert.assertEquals("left", nodesResp.get(1).get("displayName")); Assert.assertEquals("RUNNING", nodesResp.get(2).get("state")); Assert.assertEquals("UNKNOWN", nodesResp.get(2).get("result")); Assert.assertEquals("right", nodesResp.get(2).get("displayName")); List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class); Assert.assertEquals("RUNNING", stepsResp.get(0).get("state")); Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result")); Assert.assertEquals("13", stepsResp.get(0).get("id")); Assert.assertEquals("PAUSED", stepsResp.get(2).get("state")); Assert.assertEquals("UNKNOWN", stepsResp.get(2).get("result")); Assert.assertEquals("12", stepsResp.get(2).get("id")); }