Search in sources :

Example 6 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_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");
}
Also used : Pattern(java.util.regex.Pattern) 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 7 with JobDslBuildStep

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

Example 8 with JobDslBuildStep

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

Example 9 with JobDslBuildStep

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

Example 10 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_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");
}
Also used : Pattern(java.util.regex.Pattern) JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) ListView(org.jenkinsci.test.acceptance.po.ListView) 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)

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