use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.
the class WorkflowRunTest method globalNodePropertiesInEnv.
@Test
@Issue("JENKINS-43396")
public void globalNodePropertiesInEnv() throws Exception {
DescribableList<NodeProperty<?>, NodePropertyDescriptor> original = r.jenkins.getGlobalNodeProperties();
EnvironmentVariablesNodeProperty envProp = new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("KEY", "VALUE"));
original.add(envProp);
WorkflowJob j = r.jenkins.createProject(WorkflowJob.class, "envVars");
j.setDefinition(new CpsFlowDefinition("echo \"KEY is ${env.KEY}\"", true));
WorkflowRun b = r.assertBuildStatusSuccess(j.scheduleBuild2(0));
r.assertLogContains("KEY is " + envProp.getEnvVars().get("KEY"), b);
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.
the class WorkflowRunTest method funnyParameters.
@Test
public void funnyParameters() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo \"a.b=${params['a.b']}\"", true));
p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("a.b", null)));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("a.b", "v"))));
r.assertLogContains("a.b=v", b);
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.
the class WorkflowRunTest method failedToStartRun.
@Test
@Issue("JENKINS-29221")
public void failedToStartRun() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("{{stage 'dev'\n" + "def hello = new HelloWorld()\n" + "public class HelloWorld()\n" + "{ // <- invalid class definition }\n" + "}}"));
QueueTaskFuture<WorkflowRun> workflowRunQueueTaskFuture = p.scheduleBuild2(0);
WorkflowRun run = r.assertBuildStatus(Result.FAILURE, workflowRunQueueTaskFuture.get());
// The issue was that the WorkflowRun's execution instance got initialised even though the script
// was bad and the execution never started. The fix is to ensure that it only gets initialised
// if the execution instance starts successfully i.e. in the case of this test, that it doesn't
// get initialised.
assertNull(run.getExecution());
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.
the class WorkflowRunTest method interruptCause.
@Issue("JENKINS-41276")
@Test
public void interruptCause() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
// TODO should probably be @Whitelisted
ScriptApproval.get().approveSignature("method org.jenkinsci.plugins.workflow.steps.FlowInterruptedException getCauses");
// ditto
ScriptApproval.get().approveSignature("method jenkins.model.CauseOfInterruption$UserInterruption getUser");
p.setDefinition(new CpsFlowDefinition("@NonCPS def users(e) {e.causes*.user}; try {semaphore 'wait'} catch (e) {echo(/users=${users(e)}/); throw e}", true));
final WorkflowRun b1 = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("wait/1", b1);
ACL.impersonate(User.get("dev").impersonate(), new Runnable() {
@Override
public void run() {
b1.getExecutor().doStop();
}
});
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b1));
r.assertLogContains("users=[dev]", b1);
InterruptedBuildAction iba = b1.getAction(InterruptedBuildAction.class);
assertNotNull(iba);
assertEquals(Collections.singletonList(new CauseOfInterruption.UserInterruption("dev")), iba.getCauses());
String log = JenkinsRule.getLog(b1);
assertEquals(log, 1, StringUtils.countMatches(log, jenkins.model.Messages.CauseOfInterruption_ShortDescription("dev")));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project workflow-job-plugin by jenkinsci.
the class WorkflowRunTest method interruptWithResult.
@Test
public void interruptWithResult() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("sleep 1; semaphore 'hang'", true));
WorkflowRun b1 = p.scheduleBuild2(0).waitForStart();
// TODO sleeps should not be necessary but seems to randomly fail to receive interrupt otherwise
Thread.sleep(500);
SemaphoreStep.waitForStart("hang/1", b1);
Thread.sleep(500);
Executor ex = b1.getExecutor();
assertNotNull(ex);
ex.interrupt(Result.NOT_BUILT, new CauseOfInterruption.UserInterruption("bob"));
r.assertBuildStatus(Result.NOT_BUILT, r.waitForCompletion(b1));
InterruptedBuildAction iba = b1.getAction(InterruptedBuildAction.class);
assertNotNull(iba);
assertEquals(Collections.singletonList(new CauseOfInterruption.UserInterruption("bob")), iba.getCauses());
Thread.sleep(500);
WorkflowRun b2 = p.scheduleBuild2(0).waitForStart();
assertEquals(2, b2.getNumber());
Thread.sleep(500);
SemaphoreStep.waitForStart("hang/2", b2);
Thread.sleep(500);
ex = b2.getExecutor();
assertNotNull(ex);
ex.interrupt();
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b2));
iba = b2.getAction(InterruptedBuildAction.class);
assertNull(iba);
}
Aggregations