use of hudson.model.StringParameterDefinition in project jenkins by jenkinsci.
the class LauncherTest method overwriteSystemEnvVars.
@Issue("JENKINS-19926")
@Test
public void overwriteSystemEnvVars() throws Exception {
Map<String, String> env = new HashMap<>();
env.put("jenkins_19926", "original value");
Slave slave = rule.createSlave(new EnvVars(env));
FreeStyleProject project = rule.createFreeStyleProject();
project.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("jenkins_19926", "${jenkins_19926} and new value")));
final CommandInterpreter script = Functions.isWindows() ? new BatchFile("echo %jenkins_19926%") : new Shell("echo ${jenkins_19926}");
project.getBuildersList().add(script);
project.setAssignedNode(slave.getComputer().getNode());
FreeStyleBuild build = rule.buildAndAssertSuccess(project);
rule.assertLogContains("original value and new value", build);
}
use of hudson.model.StringParameterDefinition in project jenkins by jenkinsci.
the class BuildCommandTest method parameters.
@Test
public void parameters() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("key", null)));
assertThat(new CLICommandInvoker(j, new BuildCommand()).invokeWithArgs("-s", "-p", "key=foobar", p.getName()), CLICommandInvoker.Matcher.succeeded());
FreeStyleBuild b = j.assertBuildStatusSuccess(p.getBuildByNumber(1));
assertEquals("foobar", b.getAction(ParametersAction.class).getParameter("key").getValue());
}
use of hudson.model.StringParameterDefinition in project jenkins by jenkinsci.
the class RetainVariablesLocalRuleTest method retainVariable_removeModifiedSystemEnv_batch.
@Test
public void retainVariable_removeModifiedSystemEnv_batch() throws Exception {
assumeTrue(Functions.isWindows());
FreeStyleProject p = j.createFreeStyleProject();
BatchFile batch = new BatchFile("echo \"begin %what% [=[%path%]=] end\"");
p.getBuildersList().add(batch);
p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("what", "Hello"), // override the System env variable
new StringParameterDefinition("path", null)));
String initialValueOfPath;
{
// no attempt to modify path (except other plugin)
RetainVariablesLocalRule localRule = new RetainVariablesLocalRule();
localRule.setVariables("what");
batch.setConfiguredLocalRules(Collections.singletonList(localRule));
FreeStyleBuild build = j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, (Cause) null, new ParametersAction(new StringParameterValue("what", "hello"))));
initialValueOfPath = findStringEnclosedBy(build, "[=[", "]=]");
assertContainsSequentially(build, "hello");
}
{
// does not accept modification of path
RetainVariablesLocalRule localRule = new RetainVariablesLocalRule();
localRule.setVariables("what");
batch.setConfiguredLocalRules(Collections.singletonList(localRule));
FreeStyleBuild build = j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, (Cause) null, new ParametersAction(new StringParameterValue("what", "hello"), new StringParameterValue("path", "modificationOfPath"))));
// potentially plugins modified the path also
assertContainsSequentially(build, "begin hello");
assertContainsSequentially(build, initialValueOfPath);
assertDoesNotContainsSequentially(build, "modificationOfPath");
}
{
// accept modification of path
RetainVariablesLocalRule localRule = new RetainVariablesLocalRule();
localRule.setVariables("what path");
batch.setConfiguredLocalRules(Collections.singletonList(localRule));
FreeStyleBuild build = j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, (Cause) null, new ParametersAction(new StringParameterValue("what", "hello"), new StringParameterValue("path", "modificationOfPath;$PATH"))));
// potentially plugins modified the path also
assertContainsSequentially(build, "begin hello");
assertContainsSequentially(build, "modificationOfPath");
}
}
use of hudson.model.StringParameterDefinition in project jenkins by jenkinsci.
the class RetainVariablesLocalRuleTest method multipleBuildSteps_haveSeparateRules_shell.
@Test
public void multipleBuildSteps_haveSeparateRules_shell() throws Exception {
assumeFalse(Functions.isWindows());
FreeStyleProject p = j.createFreeStyleProject();
Shell batch1 = new Shell("echo \"Step1: $what $who\"");
Shell batch2 = new Shell("echo \"Step2: $what $who\"");
p.getBuildersList().add(batch1);
p.getBuildersList().add(batch2);
p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("what", "Hello"), new StringParameterDefinition("who", "World")));
{
// two steps with a specified local rule on each, there is not interaction
RetainVariablesLocalRule localRule1 = new RetainVariablesLocalRule();
// take care to allow the PATH to be used, without that the cmd is not found
localRule1.setVariables("what");
batch1.setConfiguredLocalRules(Collections.singletonList(localRule1));
RetainVariablesLocalRule localRule2 = new RetainVariablesLocalRule();
// take care to allow the PATH to be used, without that the cmd is not found
localRule2.setVariables("who");
batch2.setConfiguredLocalRules(Collections.singletonList(localRule2));
FreeStyleBuild build = j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, (Cause) null, new ParametersAction(new StringParameterValue("what", "hello"), new StringParameterValue("who", "world"))));
assertContainsSequentially(build, "Step1: hello");
// due to the display of each command, the log displays `echo "Step2: world"`, then on the next line the result
assertDoesNotContainsSequentially(build, "world", "Step2:", "world");
assertContainsSequentially(build, "Step2: world");
}
}
use of hudson.model.StringParameterDefinition in project jenkins by jenkinsci.
the class RetainVariablesLocalRuleTest method retainVariable_removeUnwantedVariables_batch.
@Test
public void retainVariable_removeUnwantedVariables_batch() throws Exception {
assumeTrue(Functions.isWindows());
FreeStyleProject p = j.createFreeStyleProject();
BatchFile batch = new BatchFile("echo \"begin %what% %who% end\"");
p.getBuildersList().add(batch);
p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("what", "Hello"), new StringParameterDefinition("who", "World")));
{
// the rule allows the user to retain only a subset of variable
RetainVariablesLocalRule localRule = new RetainVariablesLocalRule();
localRule.setVariables("what");
batch.setConfiguredLocalRules(Collections.singletonList(localRule));
FreeStyleBuild build = j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, (Cause) null, new ParametersAction(new StringParameterValue("what", "hello"), new StringParameterValue("who", "world"))));
assertContainsSequentially(build, "begin hello end");
assertDoesNotContainsSequentially(build, "world");
}
{
// the rule allows the user to retain only a subset of variable (second example)
RetainVariablesLocalRule localRule = new RetainVariablesLocalRule();
localRule.setVariables("who");
batch.setConfiguredLocalRules(Collections.singletonList(localRule));
FreeStyleBuild build = j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, (Cause) null, new ParametersAction(new StringParameterValue("what", "hello"), new StringParameterValue("who", "world"))));
assertContainsSequentially(build, "begin world end");
assertDoesNotContainsSequentially(build, "hello");
}
}
Aggregations