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());
}
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());
}
}
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);
}
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);
}
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");
}
Aggregations