use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method getPipelineJobActivities.
@Test
public void getPipelineJobActivities() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build1'); " + " echo ('Building'); " + " stage ('Test1'); " + " sleep 10000 " + " echo ('Testing'); " + "}"));
job1.setConcurrentBuild(false);
WorkflowRun r = job1.scheduleBuild2(0).waitForStart();
job1.scheduleBuild2(0);
List l = request().get("/organizations/jenkins/pipelines/pipeline1/activities").build(List.class);
Assert.assertEquals(2, l.size());
Assert.assertEquals("io.jenkins.blueocean.service.embedded.rest.QueueItemImpl", ((Map) l.get(0)).get("_class"));
Assert.assertEquals("io.jenkins.blueocean.rest.impl.pipeline.PipelineRunImpl", ((Map) l.get(1)).get("_class"));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class AbstractRunImplTest method replayRunTest.
// Disabled, see JENKINS-36453
@Test
@Ignore
public void replayRunTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
j.createOnlineSlave(Label.get("remote"));
job1.setDefinition(new CpsFlowDefinition("node('remote') {\n" + " ws {\n" + " git($/" + sampleRepo + "/$)\n" + " }\n" + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
sampleRepo.write("file1", "");
sampleRepo.git("add", "file1");
sampleRepo.git("commit", "--message=init");
WorkflowRun b2 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b2);
Assert.assertNotEquals(new PipelineRunImpl(b1, null, null).getCommitId(), new PipelineRunImpl(b2, null, null).getCommitId());
request().post("/organizations/jenkins/pipelines/pipeline1/runs/1/replay").build(String.class);
j.waitForCompletion(job1.getLastBuild());
Map r = request().get("/organizations/jenkins/pipelines/pipeline1/runs/3/").build(Map.class);
assertEquals(r.get("commitId"), new PipelineRunImpl(b2, null, null).getCommitId());
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-cps-plugin by jenkinsci.
the class ArgumentsActionImplTest method testReallyUnusualStepInstantiations.
@Test
public void testReallyUnusualStepInstantiations() throws Exception {
WorkflowJob job = r.jenkins.createProject(WorkflowJob.class, "unusualInstantiation");
job.setDefinition(new CpsFlowDefinition(" node() {\n" + " writeFile text: 'hello world', file: 'msg.out'\n" + // note, not whitelisted
" step(new hudson.tasks.ArtifactArchiver('msg.out'))\n" + "}", false));
WorkflowRun run = r.buildAndAssertSuccess(job);
LinearScanner scan = new LinearScanner();
FlowNode testNode = scan.findFirstMatch(run.getExecution().getCurrentHeads().get(0), new NodeStepTypePredicate("step"));
ArgumentsAction act = testNode.getPersistentAction(ArgumentsAction.class);
Assert.assertNotNull(act);
Object delegate = act.getArgumentValue("delegate");
Assert.assertThat(delegate, instanceOf(ArtifactArchiver.class));
Assert.assertEquals("msg.out", ((ArtifactArchiver) delegate).getArtifacts());
Assert.assertFalse(((ArtifactArchiver) delegate).isFingerprint());
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-cps-plugin by jenkinsci.
the class ArgumentsActionImplTest method simpleSemaphoreStep.
@Test
public void simpleSemaphoreStep() throws Exception {
WorkflowJob job = r.jenkins.createProject(WorkflowJob.class, "p");
job.setDefinition(new CpsFlowDefinition("semaphore 'wait'"));
WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get();
SemaphoreStep.waitForStart("wait/1", run);
FlowNode semaphoreNode = run.getExecution().getCurrentHeads().get(0);
CpsThread thread = CpsThread.current();
SemaphoreStep.success("wait/1", null);
r.waitForCompletion(run);
testDeserialize(run.getExecution());
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-cps-plugin by jenkinsci.
the class ArgumentsActionImplTest method testBasicCredentials.
@Test
public void testBasicCredentials() throws Exception {
String username = "bob";
String password = "s3cr3t";
UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "test", "sample", username, password);
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
WorkflowJob job = r.jenkins.createProject(WorkflowJob.class, "credentialed");
job.setDefinition(new CpsFlowDefinition("node{ withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'test',\n" + " usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {\n" + " //available as an env variable, but will be masked if you try to print it out any which way\n" + " echo \"$PASSWORD'\" \n" + " echo \"${env.USERNAME}\"\n" + " echo \"bob\"\n" + "} }\n" + "withCredentials([usernamePassword(credentialsId: 'test', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {\n" + " echo \"${env.USERNAME} ${env.PASSWORD}\"\n" + "}"));
WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get();
r.waitForCompletion(run);
FlowExecution exec = run.getExecution();
String log = r.getLog(run);
ForkScanner scanner = new ForkScanner();
List<FlowNode> filtered = scanner.filteredNodes(exec, new DescriptorMatchPredicate(BindingStep.DescriptorImpl.class));
// Check the binding step is OK
Assert.assertEquals(8, filtered.size());
FlowNode node = Collections2.filter(filtered, FlowScanningUtils.hasActionPredicate(ArgumentsActionImpl.class)).iterator().next();
ArgumentsActionImpl act = node.getPersistentAction(ArgumentsActionImpl.class);
Assert.assertNotNull(act.getArgumentValue("bindings"));
Assert.assertNotNull(act.getArguments().get("bindings"));
// Test that masking really does mask bound credentials appropriately
filtered = scanner.filteredNodes(exec, new DescriptorMatchPredicate(EchoStep.DescriptorImpl.class));
for (FlowNode f : filtered) {
act = f.getPersistentAction(ArgumentsActionImpl.class);
Assert.assertEquals(ArgumentsAction.NotStoredReason.MASKED_VALUE, act.getArguments().get("message"));
Assert.assertNull(ArgumentsAction.getStepArgumentsAsString(f));
}
List<FlowNode> allStepped = scanner.filteredNodes(run.getExecution().getCurrentHeads(), FlowScanningUtils.hasActionPredicate(ArgumentsActionImpl.class));
// One ArgumentsActionImpl per block or atomic step
Assert.assertEquals(6, allStepped.size());
testDeserialize(exec);
}
Aggregations