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