Search in sources :

Example 1 with JobDslBuildStep

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));
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 2 with JobDslBuildStep

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;
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob)

Example 3 with JobDslBuildStep

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"));
}
Also used : PluginManager(org.jenkinsci.test.acceptance.po.PluginManager) PluginSpec(org.jenkinsci.test.acceptance.update_center.PluginSpec) JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 4 with JobDslBuildStep

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();
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 5 with JobDslBuildStep

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();
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Aggregations

JobDslBuildStep (org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep)23 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)23 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)17 Test (org.junit.Test)17 Build (org.jenkinsci.test.acceptance.po.Build)13 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)10 GlobalSecurityConfig (org.jenkinsci.test.acceptance.po.GlobalSecurityConfig)5 Pattern (java.util.regex.Pattern)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ScriptApproval (org.jenkinsci.test.acceptance.plugins.script_security.ScriptApproval)2 Folder (org.jenkinsci.test.acceptance.po.Folder)1 Job (org.jenkinsci.test.acceptance.po.Job)1 ListView (org.jenkinsci.test.acceptance.po.ListView)1 PluginManager (org.jenkinsci.test.acceptance.po.PluginManager)1 PluginSpec (org.jenkinsci.test.acceptance.update_center.PluginSpec)1