use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.
the class CLITest method reload.
@Issue("JENKINS-30785")
@Test
public void reload() throws Exception {
WorkflowJob p = r.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo 'first version'", true));
r.assertLogContains("first version", r.buildAndAssertSuccess(p));
File configXml = new File(p.getRootDir(), "config.xml");
FileUtils.write(configXml, FileUtils.readFileToString(configXml).replace("first version", "second version"));
assertThat(new CLICommandInvoker(r, "reload-job").invokeWithArgs("p"), CLICommandInvoker.Matcher.succeededSilently());
r.assertLogContains("second version", r.buildAndAssertSuccess(p));
CLICommandInvoker.Result res = new CLICommandInvoker(r, "reload-job").invokeWithArgs("q");
assertThat(res, CLICommandInvoker.Matcher.failedWith(3));
assertThat(res.stderr(), containsString("No such item āqā exists. Perhaps you meant āpā?"));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.
the class CLITest method setBuildDescriptionAndDisplayName.
@Test
public void setBuildDescriptionAndDisplayName() throws Exception {
WorkflowJob p = r.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("", true));
WorkflowRun b = r.buildAndAssertSuccess(p);
assertThat(new CLICommandInvoker(r, "set-build-description").invokeWithArgs("p", "1", "the desc"), CLICommandInvoker.Matcher.succeededSilently());
assertEquals("the desc", b.getDescription());
assertThat(new CLICommandInvoker(r, "set-build-display-name").invokeWithArgs("p", "1", "the name"), CLICommandInvoker.Matcher.succeededSilently());
assertEquals("the name", b.getDisplayName());
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.
the class ReverseBuildTriggerTest method upstreamMapRebuilding.
@Issue("JENKINS-33971")
@Test
public void upstreamMapRebuilding() throws Exception {
story.then(r -> {
r.jenkins.setQuietPeriod(0);
WorkflowJob us = r.jenkins.createProject(WorkflowJob.class, "us");
us.setDefinition(new CpsFlowDefinition("", true));
// force it to load after ds when we restart
us.addProperty(new SlowToLoad());
WorkflowJob ds = r.jenkins.createProject(WorkflowJob.class, "ds");
ds.setDefinition(new CpsFlowDefinition("", true));
ds.addTrigger(new ReverseBuildTrigger("us", Result.SUCCESS));
r.assertBuildStatusSuccess(us.scheduleBuild2(0));
r.waitUntilNoActivity();
WorkflowRun ds1 = ds.getLastCompletedBuild();
assertNotNull(ds1);
assertEquals(1, ds1.getNumber());
});
story.then(r -> {
WorkflowJob us = r.jenkins.getItemByFullName("us", WorkflowJob.class);
assertNotNull(us);
WorkflowJob ds = r.jenkins.getItemByFullName("ds", WorkflowJob.class);
assertNotNull(ds);
r.assertBuildStatusSuccess(us.scheduleBuild2(0));
r.waitUntilNoActivity();
WorkflowRun ds2 = ds.getLastCompletedBuild();
assertNotNull(ds2);
assertEquals(2, ds2.getNumber());
});
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.
the class WorkflowRunRestartTest method flowExecutionListener.
@Issue("JENKINS-43055")
@Test
public void flowExecutionListener() throws Exception {
story.then(r -> {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo 'Running for listener'\n" + "sleep 0\n" + "semaphore 'wait'\n" + "sleep 0\n" + "semaphore 'post-resume'\n" + "sleep 0\n" + "error 'fail'\n", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("wait/1", b);
ExecListener listener = ExtensionList.lookup(FlowExecutionListener.class).get(ExecListener.class);
assertNotNull(listener);
assertEquals(1, listener.started);
assertEquals(0, listener.resumed);
assertEquals(0, listener.finished);
});
story.then(r -> {
WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getLastBuild();
assertTrue(b.isBuilding());
SemaphoreStep.success("wait/1", null);
SemaphoreStep.waitForStart("post-resume/1", b);
ExecListener listener = ExtensionList.lookup(FlowExecutionListener.class).get(ExecListener.class);
assertNotNull(listener);
assertEquals(0, listener.started);
assertEquals(1, listener.resumed);
assertEquals(0, listener.finished);
SemaphoreStep.success("post-resume/1", null);
r.assertBuildStatus(Result.FAILURE, r.waitForCompletion(b));
r.assertLogContains("Running for listener", b);
assertEquals(0, listener.started);
assertEquals(1, listener.resumed);
assertEquals(1, listener.finished);
assertTrue(listener.graphListener.wasCalledBeforeExecListener);
});
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.
the class BuildTriggerTest method smokes.
@Issue("JENKINS-28113")
@Test
public void smokes() throws Exception {
BuildTrigger.DescriptorImpl d = r.jenkins.getDescriptorByType(BuildTrigger.DescriptorImpl.class);
FreeStyleProject us = r.createProject(FreeStyleProject.class, "us");
WorkflowJob ds = r.createProject(WorkflowJob.class, "ds");
ds.setDefinition(new CpsFlowDefinition("", true));
assertEquals(Collections.singletonList("ds"), d.doAutoCompleteChildProjects("d", us, r.jenkins).getValues());
FormValidation validation = d.doCheck(us, "ds");
assertEquals(validation.renderHtml(), FormValidation.Kind.OK, validation.kind);
us.getPublishersList().add(new BuildTrigger("ds", Result.SUCCESS));
r.jenkins.setQuietPeriod(0);
FreeStyleBuild us1 = r.buildAndAssertSuccess(us);
r.waitUntilNoActivity();
WorkflowRun ds1 = ds.getLastBuild();
assertNotNull("triggered", ds1);
Cause.UpstreamCause cause = ds1.getCause(Cause.UpstreamCause.class);
assertNotNull(cause);
assertEquals(us1, cause.getUpstreamRun());
}
Aggregations