use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.
the class BuildCommandTest method executorsAliveOnParameterWithNullDefaultValue.
@Issue("JENKINS-15094")
@Test
public void executorsAliveOnParameterWithNullDefaultValue() throws Exception {
DumbSlave slave = j.createSlave();
FreeStyleProject project = j.createFreeStyleProject("foo");
project.setAssignedNode(slave);
// Create test parameter with Null default value
NullDefaultValueParameterDefinition nullDefaultDefinition = new NullDefaultValueParameterDefinition();
ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(new StringParameterDefinition("string", "defaultValue", "description"), nullDefaultDefinition);
project.addProperty(pdp);
CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
project.getBuildersList().add(builder);
// Warmup
j.buildAndAssertSuccess(project);
for (Executor exec : slave.toComputer().getExecutors()) {
assertTrue("Executor has died before the test start: " + exec, exec.isActive());
}
// Create CLI & run command
CLICommandInvoker invoker = new CLICommandInvoker(j, new BuildCommand());
CLICommandInvoker.Result result = invoker.invokeWithArgs("foo", "-p", "string=value");
assertThat(result, failedWith(2));
assertThat(result.stderr(), containsString("ERROR: No default value for the parameter 'FOO'."));
// Give the job 5 seconds to be submitted
Thread.sleep(5000);
assertNull("Build should not be scheduled", j.jenkins.getQueue().getItem(project));
assertNull("Build should not be scheduled", project.getBuildByNumber(2));
// Check executors health after a timeout
for (Executor exec : slave.toComputer().getExecutors()) {
assertTrue("Executor is dead: " + exec, exec.isActive());
}
}
use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project copyartifact-plugin by jenkinsci.
the class CopyArtifactTest method testEnvDataInMavenProject.
@Issue("JENKINS-16028")
@Test
public void testEnvDataInMavenProject() throws Exception {
FreeStyleProject upstream = rule.createFreeStyleProject("upstream");
upstream.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar"));
upstream.getPublishersList().add(new ArtifactArchiver("**/*", "", false, false));
FreeStyleBuild upstreamBuild = upstream.scheduleBuild2(0).get();
rule.assertBuildStatusSuccess(upstreamBuild);
MavenModuleSet downstream = setupMavenJob();
downstream.getPrebuilders().add(CopyArtifactUtil.createCopyArtifact("upstream", "", new SpecificBuildSelector(Integer.toString(upstreamBuild.getNumber())), "**/*", "", "", false, false, false));
CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder();
downstream.getPrebuilders().add(envStep);
MavenModuleSetBuild downstreamBuild = downstream.scheduleBuild2(0).get();
rule.assertBuildStatusSuccess(downstreamBuild);
assertFile(true, "artifact.txt", downstreamBuild);
assertEquals(Integer.toString(upstreamBuild.getNumber()), envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_UPSTREAM"));
}
use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project copyartifact-plugin by jenkinsci.
the class CopyArtifactTest method testResultVariableSuffix.
@Test
public void testResultVariableSuffix() throws Exception {
FreeStyleProject srcProject = createArtifactProject("SRC-PROJECT1");
FreeStyleBuild srcBuild = srcProject.scheduleBuild2(0).get();
rule.assertBuildStatusSuccess(srcBuild);
// if no result variable suffix is provided
// the default suffix (SRC_PROJECT) is used.
{
FreeStyleProject p = rule.createFreeStyleProject();
p.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(srcProject.getFullName(), // parameters
null, new PermalinkBuildSelector("lastStableBuild"), // filter
"*.txt", // excludes
"", // target
"", // flatten
false, // optional
false, // fingerprintArtifacts
true, // resultVariableSuffix
""));
CaptureEnvironmentBuilder ceb = new CaptureEnvironmentBuilder();
p.getBuildersList().add(ceb);
rule.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertEquals(Integer.toString(srcBuild.getNumber()), ceb.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_SRC_PROJECT_"));
}
// if result variable suffix is provided
// it is used for the variable name to store.
{
FreeStyleProject p = rule.createFreeStyleProject();
p.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(srcProject.getFullName(), // parameters
null, new PermalinkBuildSelector("lastStableBuild"), // filter
"*.txt", // excludes
"", // target
"", // flatten
false, // optional
false, // fingerprintArtifacts
true, // resultVariableSuffix
"DEST1"));
CaptureEnvironmentBuilder ceb = new CaptureEnvironmentBuilder();
p.getBuildersList().add(ceb);
rule.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertEquals(Integer.toString(srcBuild.getNumber()), ceb.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_DEST1"));
assertNull(ceb.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_SRC_PROJECT_"));
}
// if result variable suffix is invalid,
// the default suffix (SRC_PROJECT) is used.
{
FreeStyleProject p = rule.createFreeStyleProject();
p.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(srcProject.getFullName(), // parameters
null, new PermalinkBuildSelector("lastStableBuild"), // filter
"*.txt", // excludes
"", // target
"", // flatten
false, // optional
false, // fingerprintArtifacts
true, // resultVariableSuffix
"= =!?"));
CaptureEnvironmentBuilder ceb = new CaptureEnvironmentBuilder();
p.getBuildersList().add(ceb);
rule.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertEquals(Integer.toString(srcBuild.getNumber()), ceb.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_SRC_PROJECT_"));
}
}
use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project copyartifact-plugin by jenkinsci.
the class BuildSelectorParameterTest method testParameter.
/**
* Verify BuildSelectorParameter works via HTML form, http POST and CLI.
*/
@Test
public void testParameter() throws Exception {
FreeStyleProject job = rule.createFreeStyleProject();
job.addProperty(new ParametersDefinitionProperty(new BuildSelectorParameter("SELECTOR", new StatusBuildSelector(false), "foo")));
CaptureEnvironmentBuilder ceb = new CaptureEnvironmentBuilder();
job.getBuildersList().add(ceb);
// Run via UI (HTML form)
WebClient wc = rule.createWebClient();
WebClientOptions wco = wc.getOptions();
// Jenkins sends 405 response for GET of build page.. deal with that:
wco.setThrowExceptionOnFailingStatusCode(false);
wco.setPrintContentOnFailingStatusCode(false);
HtmlForm form = wc.getPage(job, "build").getFormByName("parameters");
form.getSelectByName("").getOptionByText("Specific build").setSelected(true);
wc.waitForBackgroundJavaScript(10000);
form.getInputByName("_.buildNumber").setValueAttribute("6");
rule.submit(form);
rule.waitUntilNoActivity();
assertEquals("<SpecificBuildSelector><buildNumber>6</buildNumber></SpecificBuildSelector>", ceb.getEnvVars().get("SELECTOR").replaceAll("\\s+", ""));
job.getBuildersList().replace(ceb = new CaptureEnvironmentBuilder());
// Run via HTTP POST (buildWithParameters)
WebRequest post = new WebRequest(new URL(rule.getURL(), job.getUrl() + "/buildWithParameters"), HttpMethod.POST);
wc.addCrumb(post);
String xml = "<StatusBuildSelector><stable>true</stable></StatusBuildSelector>";
post.setRequestParameters(Arrays.asList(new NameValuePair("SELECTOR", xml), post.getRequestParameters().get(0)));
wc.getPage(post);
rule.waitUntilNoActivity();
assertEquals(xml, ceb.getEnvVars().get("SELECTOR"));
job.getBuildersList().replace(ceb = new CaptureEnvironmentBuilder());
// Run via CLI
assertThat(new CLICommandInvoker(rule, "build").invokeWithArgs(job.getFullName(), "-p", "SELECTOR=<SavedBuildSelector/>"), CLICommandInvoker.Matcher.succeeded());
rule.waitUntilNoActivity();
assertEquals("<SavedBuildSelector/>", ceb.getEnvVars().get("SELECTOR"));
}
Aggregations