use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_save_configurations.
/**
* Verifies that all configurations, done on the job configuration page,
* are saved correctly.
*/
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm" })
public void should_save_configurations() {
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScriptTargetsOnFilesystem("JobTest.groovy", "AnotherJobTest.groovy");
jobDsl.setIgnoreMissingFiles(true);
jobDsl.setIgnoreExisting(true);
jobDsl.setRemovedJobAction(JobDslRemovedJobAction.DELETE);
jobDsl.setRemovedViewAction(JobDslRemovedViewAction.DELETE);
jobDsl.setRemovedConfigFilesAction(JobDslRemovedConfigFilesAction.DELETE);
jobDsl.setLookupStrategy(JobDslLookupStrategy.SEED_JOB);
jobDsl.setAdditionalClasspath("path1", "path2");
jobDsl.setFailOnMissingPlugin(true);
jobDsl.setUnstableOnDeprecation(true);
seedJob.save();
seedJob.configure();
assertThat(jobDsl.isLookOnFilesystem(), is(true));
assertThat(jobDsl.getScriptTargetsOnFilesystem(), equalTo(new String[] { "JobTest.groovy", "AnotherJobTest.groovy" }));
assertThat(jobDsl.isIgnoreMissingFiles(), is(true));
assertThat(jobDsl.isIgnoreExisting(), is(true));
assertThat(jobDsl.getRemovedJobAction(), equalTo(JobDslRemovedJobAction.DELETE));
assertThat(jobDsl.getRemovedViewAction(), equalTo(JobDslRemovedViewAction.DELETE));
assertThat(jobDsl.getRemovedConfigFilesAction(), equalTo(JobDslRemovedConfigFilesAction.DELETE));
assertThat(jobDsl.getLookupStrategy(), equalTo(JobDslLookupStrategy.SEED_JOB));
assertThat(jobDsl.getAdditionalClasspath(), equalTo(new String[] { "path1", "path2" }));
assertThat(jobDsl.isFailOnMissingPlugin(), is(true));
assertThat(jobDsl.isUnstableOnDeprecation(), is(true));
String script = "job('JobDSL-Test') {\n" + " description('This is a description.')\n" + "}";
jobDsl.setScript(script);
seedJob.save();
seedJob.configure();
assertThat(jobDsl.isUseScriptText(), is(true));
assertThat(jobDsl.getScript(), equalTo(script));
setUpSecurity();
jenkins.login().doLogin(ADMIN);
seedJob.configure(() -> jobDsl.setUseSandbox(true));
seedJob.configure();
assertThat(jobDsl.isUseSandbox(), is(true));
}
use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method executeRemovedJobAction.
/**
* Let a seed job run a Job DSL script that do not reference a previous generated job anymore.
* @param action The action what to do when a previously generated job is not referenced anymore.
* @return The executed seed job.
*/
private FreeStyleJob executeRemovedJobAction(JobDslRemovedJobAction action) {
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("job('Old_Job')");
seedJob.save();
seedJob.scheduleBuild().shouldSucceed();
seedJob.configure(() -> {
jobDsl.setScript("job('New_Job')");
jobDsl.setRemovedJobAction(action);
});
return seedJob;
}
use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_fail_on_missing_plugin.
/**
* Verifies whether the build will be marked as failed or unstable if a plugin must
* be installed to support all features used in the DSL script.
*/
@Test
public void should_fail_on_missing_plugin() {
assumeTrue("This test requires a restartable Jenkins", jenkins.canRestart());
// check if plugin is installed. if true, disable plugin
PluginSpec pluginSpec = new PluginSpec("chucknorris");
PluginManager pm = jenkins.getPluginManager();
if (pm.isInstalled(pluginSpec)) {
pm.enablePlugin(pluginSpec.getName(), false);
jenkins.restart();
}
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("job('New_Job') {\n" + " publishers {\n" + " chucknorris()\n" + " }\n" + "}");
seedJob.save();
Build build = seedJob.scheduleBuild().shouldBeUnstable();
assertThat(build.getConsole(), containsString("plugin 'chucknorris' needs to be installed"));
seedJob.configure(() -> jobDsl.setFailOnMissingPlugin(true));
build = seedJob.scheduleBuild().shouldFail();
assertThat(build.getConsole(), containsString("plugin 'chucknorris' needs to be installed"));
}
use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_ignore_missing_files.
/**
* Verifies whether missing files will be ignored or fail the build step.
* If 'Ignore missing files' is checked, missing files are ignored.
* Otherwise the build step will fail.
*/
@Test
public void should_ignore_missing_files() {
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScriptTargetsOnFilesystem("CreateFolder.groovy");
seedJob.save();
seedJob.scheduleBuild().shouldFail();
seedJob.configure(() -> jobDsl.setIgnoreMissingFiles(true));
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_run_grooy_sandbox_as_particular_user.
/**
* Verifies that Groovy sandbox can only used if 'Access Control for Builds'
* is configured. The DSL job needs to run as a particular user.
*/
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm", "authorize-project" })
public void should_run_grooy_sandbox_as_particular_user() {
GlobalSecurityConfig sc = setUpSecurity();
jenkins.login().doLogin(USER);
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("job('New_Job')");
jobDsl.setUseSandbox(true);
seedJob.save();
// Build should fail because script runs in sandbox but no particular user is specified
// which should run the build
Build build = seedJob.scheduleBuild().shouldFail();
assertThat(build.getConsole(), containsString("You must configure the DSL job to run as a specific user in order to use the Groovy sandbox"));
runBuildAsUserWhoTriggered(sc);
jenkins.login().doLogin(USER);
// Build should succeed because now a particular user is specified
seedJob.scheduleBuild().shouldSucceed();
}
Aggregations