Search in sources :

Example 46 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project badge-plugin by jenkinsci.

the class AddBadgeStepTest method addBadge.

private void addBadge(boolean inNode) throws Exception {
    String icon = UUID.randomUUID().toString();
    String text = UUID.randomUUID().toString();
    String link = UUID.randomUUID().toString();
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    String script = "addBadge(icon:\"" + icon + "\",  text:\"" + text + "\",  link:\"" + link + "\")";
    if (inNode) {
        script = "node() {" + script + "}";
    }
    p.setDefinition(new CpsFlowDefinition(script, true));
    WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    List<BuildBadgeAction> badgeActions = b.getBadgeActions();
    assertEquals(1, badgeActions.size());
    BadgeAction action = (BadgeAction) badgeActions.get(0);
    assertTrue(action.getIconPath().endsWith(icon));
    assertEquals(text, action.getText());
    assertEquals(link, action.getLink());
}
Also used : BuildBadgeAction(hudson.model.BuildBadgeAction) BadgeAction(com.jenkinsci.plugins.badge.action.BadgeAction) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BuildBadgeAction(hudson.model.BuildBadgeAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Example 47 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project badge-plugin by jenkinsci.

the class RemoveBadgesStepTest method removeBadges.

private void removeBadges(String badgeScriptPrefix, String removeScript, String... remainingBadgeIds) throws Exception {
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    String script = badgeScriptPrefix + ", id: 'a')\n" + badgeScriptPrefix + ", id: 'b')\n" + removeScript;
    p.setDefinition(new CpsFlowDefinition(script, true));
    WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    List<AbstractBadgeAction> badgeActions = b.getActions(AbstractBadgeAction.class);
    assertEquals(remainingBadgeIds.length, badgeActions.size());
    for (int i = 0; i < remainingBadgeIds.length; i++) {
        assertEquals(remainingBadgeIds[i], badgeActions.get(i).getId());
    }
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) AbstractBadgeAction(com.jenkinsci.plugins.badge.action.AbstractBadgeAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Example 48 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project dependency-check-plugin by jenkinsci.

the class DependencyCheckWorkflowTest method dependencyCheckPublisherWorkflowStep.

/**
 * Run a workflow job using {@link org.jenkinsci.plugins.DependencyCheck.DependencyCheckPublisher} and check for success.
 */
@Test
public void dependencyCheckPublisherWorkflowStep() throws Exception {
    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "dependencyCheckWorkPublisherWorkflowStep");
    FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job);
    FilePath report = workspace.child("target").child("dependency-check-report.xml");
    report.copyFrom(DependencyCheckWorkflowTest.class.getResourceAsStream("/org/jenkinsci/plugins/dependencycheck/parser/dependency-check-report2.xml"));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  step([$class: 'DependencyCheckPublisher'])\n" + "}\n", true));
    jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    DependencyCheckResultAction result = job.getLastBuild().getAction(DependencyCheckResultAction.class);
    assertTrue(result.getResult().getAnnotations().size() == 2);
}
Also used : FilePath(hudson.FilePath) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) DependencyCheckResultAction(org.jenkinsci.plugins.DependencyCheck.DependencyCheckResultAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Test(org.junit.Test)

Example 49 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.

the class WorkflowRunTest method basics.

@Test
public void basics() throws Exception {
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition("println('hello')"));
    WorkflowRun b1 = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    assertFalse(b1.isBuilding());
    assertFalse(b1.isInProgress());
    assertFalse(b1.isLogUpdated());
    assertTrue(b1.getDuration() > 0);
    WorkflowRun b2 = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    assertEquals(b1, b2.getPreviousBuild());
    assertEquals(null, b1.getPreviousBuild());
    r.assertLogContains("hello", b1);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Test(org.junit.Test)

Example 50 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.

the class WorkflowRunTest method culprits.

@Test
@Issue("JENKINS-24141")
public void culprits() throws Exception {
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition("import org.jvnet.hudson.test.FakeChangeLogSCM\n" + "semaphore 'waitFirst'\n" + "def testScm = new FakeChangeLogSCM()\n" + "testScm.addChange().withAuthor(/alice$BUILD_NUMBER/)\n" + "node {\n" + "    checkout(testScm)\n" + "    semaphore 'waitSecond'\n" + "    def secondScm = new FakeChangeLogSCM()\n" + "    secondScm.addChange().withAuthor(/bob$BUILD_NUMBER/)\n" + "    checkout(secondScm)\n" + "    semaphore 'waitThird'\n" + "    def thirdScm = new FakeChangeLogSCM()\n" + "    thirdScm.addChange().withAuthor(/charlie$BUILD_NUMBER/)\n" + "    checkout(thirdScm)\n" + "}\n", false));
    WorkflowRun b1 = p.scheduleBuild2(0).waitForStart();
    SemaphoreStep.waitForStart("waitFirst/1", b1);
    assertTrue(b1.getCulpritIds().isEmpty());
    SemaphoreStep.success("waitFirst/1", null);
    SemaphoreStep.waitForStart("waitSecond/1", b1);
    assertCulprits(b1, "alice1");
    SemaphoreStep.success("waitSecond/1", null);
    SemaphoreStep.waitForStart("waitThird/1", b1);
    assertCulprits(b1, "alice1", "bob1");
    SemaphoreStep.failure("waitThird/1", new AbortException());
    r.assertBuildStatus(Result.FAILURE, r.waitForCompletion(b1));
    WorkflowRun b2 = p.scheduleBuild2(0).waitForStart();
    SemaphoreStep.waitForStart("waitFirst/2", b2);
    assertCulprits(b2, "alice1", "bob1");
    SemaphoreStep.success("waitFirst/2", null);
    SemaphoreStep.waitForStart("waitSecond/2", b2);
    assertCulprits(b2, "alice1", "bob1", "alice2");
    SemaphoreStep.success("waitSecond/2", null);
    SemaphoreStep.waitForStart("waitThird/2", b2);
    assertCulprits(b2, "alice1", "bob1", "alice2", "bob2");
    SemaphoreStep.success("waitThird/2", b2);
    r.assertBuildStatusSuccess(r.waitForCompletion(b2));
    assertCulprits(b2, "alice1", "bob1", "alice2", "bob2", "charlie2");
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) AbortException(hudson.AbortException) 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