use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_ignore_existing_jobs.
/**
* Verifies whether previously generated jobs will be ignored or updated.
* By default, all previous generated jobs will be updated.
* If existing jobs should be ignored, the plugin do not modify previous
* generated jobs.
*/
@Test
public void should_ignore_existing_jobs() {
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("job('Existing_Job') {\n" + " description('Existing description');\n" + "}");
seedJob.save();
seedJob.scheduleBuild().shouldSucceed();
FreeStyleJob existingJob = getJob("Existing_Job");
seedJob.configure(() -> {
jobDsl.setScript("job('Existing_Job') {\n" + " description('This is a description');\n" + "}");
jobDsl.setIgnoreExisting(true);
});
Build build = seedJob.scheduleBuild().shouldSucceed();
Pattern expected = Pattern.compile("Existing items:(\\s*)GeneratedJob[{]name='Existing_Job'}");
assertThat(build.getConsole(), containsRegexp(expected));
checkDescription(existingJob, "Existing description");
seedJob.configure(() -> jobDsl.setIgnoreExisting(false));
Build build2 = seedJob.scheduleBuild().shouldSucceed();
assertThat(build2.getConsole(), containsRegexp(expected));
checkDescription(existingJob, "This is a description");
}
use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method createSeedJobWithJobDsl.
private Job createSeedJobWithJobDsl(String jobDsl) {
Job seed = jenkins.jobs.create(FreeStyleJob.class, "Seed");
JobDslBuildStep jobDslBuildStep = seed.addBuildStep(JobDslBuildStep.class);
jobDslBuildStep.setScript(jobDsl);
seed.save();
return seed;
}
use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method createJobAndSetJobDslScript.
/**
* This method creates a seed job and configures it with a Job DSL script.
* @param script The Job DSL scrpt
* @return The newly created and configured seed job
*/
private FreeStyleJob createJobAndSetJobDslScript(String script, boolean isSeed) {
FreeStyleJob job;
if (isSeed) {
job = createSeedJob();
} else {
job = jenkins.jobs.create(FreeStyleJob.class);
}
JobDslBuildStep jobDsl = job.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript(script);
job.save();
return job;
}
use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_use_script_security.
/**
* Verifies that if script security for Job DSL scripts is enabled,
* scripts saved by non administrators that not run in a Groovy sandbox
* wont be executed, because they are not approved.
* If script security for Job DSL scripts is disabled, the script can be executed.
*/
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm" })
public void should_use_script_security() {
GlobalSecurityConfig sc = setUpSecurity();
jenkins.login().doLogin(USER);
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("job('New_Job')");
jobDsl.setUseSandbox(false);
seedJob.save();
// Build should fail because script is saved from non administrator an not yet approved
Build build = seedJob.scheduleBuild().shouldFail();
assertThat(build.getConsole(), containsString("script not yet approved for use"));
jenkins.logout();
jenkins.login().doLogin(ADMIN);
// Build should fail because script is saved from non administrator an not yet approved
Build build2 = seedJob.scheduleBuild().shouldFail();
assertThat(build2.getConsole(), containsString("script not yet approved for use"));
sc.configure(() -> sc.setJobDslScriptSecurity(false));
jenkins.logout();
jenkins.login().doLogin(USER);
// Build should succeed because script is approved now
seedJob.scheduleBuild().shouldSucceed();
}
use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_ignore_existing_views.
/**
* Verifies whether previously generated views will be ignored or updated.
* By default, all previous generated views will be updated.
* If existing views should be ignored, the plugin do not modify previous
* generated views.
*/
@Test
public void should_ignore_existing_views() {
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("listView('Existing_View') {\n" + " description('Existing description');\n" + "}");
seedJob.save();
seedJob.scheduleBuild().shouldSucceed();
ListView existingView = getView("Existing_View");
seedJob.configure(() -> {
jobDsl.setScript("listView('Existing_View') {\n" + " description('This is a description');\n" + "}");
jobDsl.setIgnoreExisting(true);
});
Build build = seedJob.scheduleBuild().shouldSucceed();
Pattern expected = Pattern.compile("Existing views:(\\s*)GeneratedView[{]name='Existing_View'}");
assertThat(build.getConsole(), containsRegexp(expected));
checkDescription(existingView, "Existing description");
seedJob.configure(() -> jobDsl.setIgnoreExisting(false));
Build build2 = seedJob.scheduleBuild().shouldSucceed();
assertThat(build2.getConsole(), containsRegexp(expected));
checkDescription(existingView, "This is a description");
}
Aggregations