Search in sources :

Example 1 with WorkflowJob

use of org.jenkinsci.test.acceptance.po.WorkflowJob in project acceptance-test-harness by jenkinsci.

the class AbstractAnalysisTest method createPipelineWith.

/**
 * Creates a pipeline that enables the specified {@code stepName}. The first step of the pipeline copies the
 * specified resource {@code fileName} as first instruction to the pipeline.
 *
 * @param fileName the name of the resource that will be copied to the pipeline (this file will be scanned for
 *                 warnings)
 * @param stepName the name of the publisher to run (as a pipeline step)
 * @return the created pipeline
 */
protected WorkflowJob createPipelineWith(final String fileName, final String stepName, final String additionalParameters) {
    WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
    String script = "node {\n" + job.copyResourceStep(fileName) + "  step([$class: '" + stepName + "'" + ", pattern: '**/" + FilenameUtils.getName(fileName) + "'" + additionalParameters + "])\n" + "}";
    job.script.set(script);
    job.sandbox.check();
    job.save();
    return job;
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WorkflowJob(org.jenkinsci.test.acceptance.po.WorkflowJob)

Example 2 with WorkflowJob

use of org.jenkinsci.test.acceptance.po.WorkflowJob in project acceptance-test-harness by jenkinsci.

the class AnalysisCollectorPluginTest method should_checkout_pipeline_from_git.

/**
 * Creates and builds a pipeline that is version controlled in Git. Basically the same test case as
 * {@link AbstractAnalysisTest#should_navigate_to_result_action_from_pipeline()}. Rather than using the script
 * text box a Git repository is connected.
 */
@Test
@WithPlugins({ "git", "workflow-basic-steps", "workflow-multibranch", "workflow-job", "workflow-durable-task-step" })
@WithDocker
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = { CREDENTIALS_ID, KEY_FILENAME })
public void should_checkout_pipeline_from_git() {
    String gitRepositoryUrl = createGitRepositoryInDockerContainer();
    WorkflowJob job = jenkins.getJobs().create(WorkflowJob.class);
    job.setJenkinsFileRepository(gitRepositoryUrl, CREDENTIALS_ID);
    job.save();
    Build build = buildSuccessfulJob(job);
    verifyJobResults(job, build);
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WorkflowJob(org.jenkinsci.test.acceptance.po.WorkflowJob) WithCredentials(org.jenkinsci.test.acceptance.junit.WithCredentials) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins) WithDocker(org.jenkinsci.test.acceptance.junit.WithDocker)

Example 3 with WorkflowJob

use of org.jenkinsci.test.acceptance.po.WorkflowJob in project acceptance-test-harness by jenkinsci.

the class ConfigFileProviderTest method createPipelineAndGetConsole.

private String createPipelineAndGetConsole(final MavenSettingsConfig mvnConfig) {
    final WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
    job.script.set(String.format("node {\n" + "    configFileProvider(\n" + "        [configFile(fileId: '%s', variable: 'MAVEN_SETTINGS')]) {\n" + "            \n" + "        sh 'cat $MAVEN_SETTINGS '\n" + "    }\n" + "}", mvnConfig.id()));
    job.save();
    final Build b = job.startBuild().shouldSucceed();
    return b.getConsole();
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) WorkflowJob(org.jenkinsci.test.acceptance.po.WorkflowJob)

Example 4 with WorkflowJob

use of org.jenkinsci.test.acceptance.po.WorkflowJob in project acceptance-test-harness by jenkinsci.

the class DeclarativePipelineTest method basicDeclarativeTests.

@WithPlugins("pipeline-model-definition")
@Test
public void basicDeclarativeTests() throws Exception {
    WorkflowJob helloWorldJob = jenkins.jobs.create(WorkflowJob.class);
    helloWorldJob.script.set("pipeline {\n" + "  agent none\n" + "  stages {\n" + "    stage('foo') {\n" + "      steps {\n" + "        echo 'Hello world'\n" + "      }\n" + "    }\n" + "  }\n" + "}\n");
    helloWorldJob.sandbox.check();
    helloWorldJob.save();
    Build helloWorldBuild = helloWorldJob.startBuild().shouldSucceed();
    assertThat(helloWorldBuild.getConsole(), containsRegexp("Hello world", Pattern.MULTILINE));
    MavenInstallation.installMaven(jenkins, "M3", "3.1.0");
    final DumbSlave slave = (DumbSlave) slaveController.install(jenkins).get();
    slave.configure(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            slave.labels.set("remote");
            return null;
        }
    });
    WorkflowJob toolsEnvAgentJob = jenkins.jobs.create(WorkflowJob.class);
    toolsEnvAgentJob.script.set("pipeline {\n" + "  agent { label 'remote' }\n" + "  tools {\n" + "    maven 'M3'\n" + "  }\n" + "  environment {\n" + "    FOO = 'BAR'\n" + "  }\n" + "  stages {\n" + "    stage('first') {\n" + "      steps {\n" + "        sh 'mvn --version'\n" + "      }\n" + "    }\n" + "    stage('second') {\n" + "      steps {\n" + "        echo \"FOO is ${env.FOO}\"\n" + "      }\n" + "    }\n" + "  }\n" + "}\n");
    toolsEnvAgentJob.sandbox.check();
    toolsEnvAgentJob.save();
    Build toolsEnvAgentBuild = toolsEnvAgentJob.startBuild().shouldSucceed();
    String toolsEnvAgentConsole = toolsEnvAgentBuild.getConsole();
    assertThat(toolsEnvAgentConsole, containsRegexp("\\(first\\)", Pattern.MULTILINE));
    assertThat(toolsEnvAgentConsole, containsRegexp("Apache Maven 3\\.1\\.0", Pattern.MULTILINE));
    assertThat(toolsEnvAgentConsole, containsRegexp("\\(second\\)", Pattern.MULTILINE));
    assertThat(toolsEnvAgentConsole, containsRegexp("FOO is BAR", Pattern.MULTILINE));
    WorkflowJob missingAgentJob = jenkins.jobs.create(WorkflowJob.class);
    missingAgentJob.script.set("pipeline {\n" + "  stages {\n" + "    stage('foo') {\n" + "      steps {\n" + "        echo 'Hello world'\n" + "      }\n" + "    }\n" + "  }\n" + "}\n");
    missingAgentJob.sandbox.check();
    missingAgentJob.save();
    Build missingAgentBuild = missingAgentJob.startBuild().shouldFail();
    String missingAgentConsole = missingAgentBuild.getConsole();
    assertThat(missingAgentConsole, containsRegexp("Missing required section ['\"]agent['\"]"));
    assertThat(missingAgentConsole, not(containsRegexp("Hello world")));
    WorkflowJob missingToolVersionJob = jenkins.jobs.create(WorkflowJob.class);
    missingToolVersionJob.script.set("pipeline {\n" + "  agent { label 'remote' }\n" + "  tools {\n" + "    maven 'some-other-version'\n" + "  }\n" + "  environment {\n" + "    FOO = 'BAR'\n" + "  }\n" + "  stages {\n" + "    stage('first') {\n" + "      steps {\n" + "        sh 'mvn --version'\n" + "      }\n" + "    }\n" + "    stage('second') {\n" + "      steps {\n" + "        echo \"FOO is ${env.FOO}\"\n" + "      }\n" + "    }\n" + "  }\n" + "}\n");
    missingToolVersionJob.sandbox.check();
    missingToolVersionJob.save();
    Build missingToolVersionBuild = missingToolVersionJob.startBuild().shouldFail();
    String missingToolVersionConsole = missingToolVersionBuild.getConsole();
    assertThat(missingToolVersionConsole, containsRegexp("Tool type ['\"]maven['\"] does not have an install of ['\"]some-other-version['\"] configured"));
    assertThat(missingToolVersionConsole, not(containsRegexp("FOO is BAR")));
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) WorkflowJob(org.jenkinsci.test.acceptance.po.WorkflowJob) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 5 with WorkflowJob

use of org.jenkinsci.test.acceptance.po.WorkflowJob in project acceptance-test-harness by jenkinsci.

the class ExternalWorkspaceManagerPluginTest method createWorkflowJob.

private WorkflowJob createWorkflowJob(String script) {
    WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
    job.script.set(script);
    job.save();
    return job;
}
Also used : WorkflowJob(org.jenkinsci.test.acceptance.po.WorkflowJob)

Aggregations

WorkflowJob (org.jenkinsci.test.acceptance.po.WorkflowJob)36 Test (org.junit.Test)24 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)21 Build (org.jenkinsci.test.acceptance.po.Build)19 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)14 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)8 StageView (org.jenkinsci.test.acceptance.plugins.stageview.StageView)8 Matchers.containsString (org.hamcrest.Matchers.containsString)4 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)4 Issue (org.jvnet.hudson.test.Issue)4 WithCredentials (org.jenkinsci.test.acceptance.junit.WithCredentials)3 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)3 Category (org.junit.experimental.categories.Category)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Ignore (org.junit.Ignore)2 File (java.io.File)1 IOException (java.io.IOException)1 Pattern (java.util.regex.Pattern)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 LocalController (org.jenkinsci.test.acceptance.controller.LocalController)1