use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.
the class NodeLabelParameterPluginTest method trigger_if_succeeds_with_failed_post_build_step.
/**
* This test is intended to verify that the second build is not started when the
* build already failed on the first slave in combination with the
* "run next build only if build succeeds" setting of the node parameter.
* <p/>
* As a build can fail in different stages this test simulates a FAILED result
* during the post build step. Therefore the text-finder plugin is used to
* fail the build based on a simple pattern matching with a text file copied to
* the slave's workspace.
* <p/>
* Note that in this case the main build action is still completed with status SUCCESS.
*/
@Test
@WithPlugins("text-finder")
@Issue("JENKINS-23129")
@Ignore("Until JENKINS-23129 is fixed")
public void trigger_if_succeeds_with_failed_post_build_step() throws Exception {
FreeStyleJob j = jenkins.jobs.create();
ArrayList<Node> slaves = new ArrayList<>();
slaves.add(slave.install(jenkins).get());
slaves.add(slave.install(jenkins).get());
j.configure();
// set up the node parameter
NodeParameter p = j.addParameter(NodeParameter.class);
p.setName("slavename");
p.runIfSuccess.check();
// copy the file to mark the status
j.copyResource(resource("/textfinder_plugin/textfinder-result_failed.log"));
// set up the post build action
TextFinderPublisher tf = j.addPublisher(TextFinderPublisher.class);
tf.filePath.sendKeys("textfinder-result_failed.log");
tf.regEx.sendKeys("^RESULT=SUCCESS$");
tf.succeedIfFound.click();
j.save();
// select both slaves for this build
j.startBuild(singletonMap("slavename", slaves.get(0).getName() + "," + slaves.get(1).getName())).shouldFail();
// verify failed result prevents the job to be built on further nodes.
// As the nodes get random names and the selected nodes are utilized in alphabetical order
// of their names, the first build will not necessarily be done on s1. Thus, it can only
// be verified that the job has been built on one of the slaves.
j.startBuild(singletonMap("slavename", slaves.get(0).getName() + "," + slaves.get(1).getName())).shouldFail();
assertThat(j.getNextBuildNumber(), is(2));
}
use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.
the class PrioritySorterPluginTest method saving_global_config_should_not_create_job_change.
// Reproduce regression fixed in https://github.com/jenkinsci/priority-sorter-plugin/commit/e46b2b1fbc4396f441c69692eb328fb982325572
@Test
@WithPlugins("jobConfigHistory")
public void saving_global_config_should_not_create_job_change() {
FreeStyleJob job = jenkins.jobs.create();
job.save();
JobConfigHistory action = job.action(JobConfigHistory.class);
final int expected = action.getChanges().size();
final JenkinsConfig global = jenkins.getConfigPage();
global.configure();
global.numExecutors.set(42);
global.save();
assertThat(action.getChanges().size(), equalTo(expected));
}
use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_create_job.
@Test
@WithPlugins({ "sidebar-link", "build-name-setter", "envinject" })
public void should_create_job() {
// Arrange
String jobName = "MyJob";
String jobDescription = "My sample description";
String jobDisplayName = "My job display name";
String jobLabel = "!ubuntu";
String linkUrl = "https://jenkins.io";
String linkLabel = "jenkins.io";
String jobDslScript = String.format(multiline("job('%s') {", " description('%s');", " displayName('%s');", " label('%s');", " customWorkspace('/tmp/custom-workspace')", " environmentVariables(varname: 'varval')", " properties {", " sidebarLinks {", " link('%s', '%s')", " }", " };", " wrappers { buildName('custom-name') }", " concurrentBuild();", " steps {", " shell('sleep 10')", " }", "}"), jobName, jobDescription, jobDisplayName, jobLabel, linkUrl, linkLabel);
Job seed = createSeedJobWithJobDsl(jobDslScript);
seed.startBuild().shouldSucceed();
// Verify configuration
Job job = jenkins.jobs.get(Job.class, jobName);
job.open();
assertThat(job.getDescription(), containsString(jobDescription));
assertThat(job.getDisplayName(), containsString(jobDisplayName));
assertThat(driver, hasElement(by.href(linkUrl)));
job.configure();
WebElement labelElement = driver.findElement(By.xpath("//input[@name='_.label']"));
assertEquals(jobLabel, labelElement.getAttribute("value"));
Build build = job.scheduleBuild().waitUntilStarted();
{
// Verify concurrent build
Build secondBuild = job.scheduleBuild().waitUntilStarted();
assertTrue(build.isInProgress());
assertTrue(secondBuild.isInProgress());
build.stop();
secondBuild.stop();
build.waitUntilFinished();
secondBuild.waitUntilFinished();
}
build.open();
assertThat(build.getDisplayName(), containsString("custom-name"));
build.open();
driver.findElement(By.partialLinkText("Environment Variables")).click();
assertThat(driver, hasElement(by.xpath(String.format("//tr/td[contains(text(), '%s')]", "varname"))));
assertThat(build.getConsole(), containsString("/tmp/custom-workspace"));
}
use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method job_filters_include_failed_jobs_built_at_least_once.
/**
* This test creates 3 jobs and builds 3 of them immediately. One of the fails. A list view is created with its job filter set to only
* include jobs that failed.
*/
@Test
@WithPlugins("view-job-filters")
public void job_filters_include_failed_jobs_built_at_least_once() {
List<Job> jobs = createAmountOfJobs(2, true);
Job job3 = createJobThatFails();
String jobDslScript = "listView('" + LIST_VIEW_NAME + "') {\n" + " columns {\n" + " name()\n" + " }\n" + " jobFilters {\n" + " buildTrend {\n" + " matchType(MatchType.INCLUDE_MATCHED)\n" + " buildCountType(BuildCountType.AT_LEAST_ONE)\n" + " status(BuildStatusType.FAILED)\n" + " }\n" + " }\n" + "}";
View view = openNewlyCreatedListView(jobDslScript, LIST_VIEW_NAME);
assertThat(view, not(containsJob(jobs.get(0))));
assertThat(view, not(containsJob(jobs.get(1))));
assertThat(view, containsJob(job3));
}
use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_use_script_approval.
/**
* 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.
* Administrators can approve scripts in the 'Script Approval' of the
* 'Manage Jenkins' area. Approved scripts can be executed.
*/
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm" })
public void should_use_script_approval() {
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"));
ScriptApproval sa = new ScriptApproval(jenkins);
sa.open();
sa.find(seedJob.name).approve();
jenkins.logout();
jenkins.login().doLogin(USER);
// Build should succeed because script is approved now
seedJob.scheduleBuild().shouldSucceed();
}
Aggregations