Search in sources :

Example 56 with CpsFlowDefinition

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ā€™?"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) CLICommandInvoker(hudson.cli.CLICommandInvoker) File(java.io.File) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 57 with CpsFlowDefinition

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());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) CLICommandInvoker(hudson.cli.CLICommandInvoker) Test(org.junit.Test)

Example 58 with CpsFlowDefinition

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());
    });
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) ReverseBuildTrigger(jenkins.triggers.ReverseBuildTrigger) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 59 with CpsFlowDefinition

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);
    });
}
Also used : FlowExecutionListener(org.jenkinsci.plugins.workflow.flow.FlowExecutionListener) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 60 with CpsFlowDefinition

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());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FormValidation(hudson.util.FormValidation) Cause(hudson.model.Cause) BuildTrigger(hudson.tasks.BuildTrigger) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)220 Test (org.junit.Test)210 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)182 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)124 Issue (org.jvnet.hudson.test.Issue)63 Map (java.util.Map)60 List (java.util.List)26 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 RunList (hudson.util.RunList)20 ExtensionList (hudson.ExtensionList)19 Statement (org.junit.runners.model.Statement)19 Run (hudson.model.Run)17 URL (java.net.URL)16 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)12 TaskListener (hudson.model.TaskListener)11 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)10 NodeStepTypePredicate (org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate)9 DescribeChangeSetResult (com.amazonaws.services.cloudformation.model.DescribeChangeSetResult)7 Parameter (com.amazonaws.services.cloudformation.model.Parameter)6