Search in sources :

Example 21 with StringParameterDefinition

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);
}
Also used : BatchFile(hudson.tasks.BatchFile) Shell(hudson.tasks.Shell) Slave(hudson.model.Slave) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) HashMap(java.util.HashMap) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) CommandInterpreter(hudson.tasks.CommandInterpreter) Issue(org.jvnet.hudson.test.Issue) SmokeTest(org.jvnet.hudson.test.SmokeTest) Test(org.junit.Test)

Example 22 with StringParameterDefinition

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());
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) ParametersAction(hudson.model.ParametersAction) SmokeTest(org.jvnet.hudson.test.SmokeTest) Test(org.junit.Test)

Example 23 with StringParameterDefinition

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");
    }
}
Also used : BatchFile(hudson.tasks.BatchFile) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) ParametersAction(hudson.model.ParametersAction) Test(org.junit.Test)

Example 24 with StringParameterDefinition

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");
    }
}
Also used : Shell(hudson.tasks.Shell) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) ParametersAction(hudson.model.ParametersAction) Test(org.junit.Test)

Example 25 with StringParameterDefinition

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");
    }
}
Also used : BatchFile(hudson.tasks.BatchFile) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) ParametersAction(hudson.model.ParametersAction) Test(org.junit.Test)

Aggregations

StringParameterDefinition (hudson.model.StringParameterDefinition)95 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)82 Test (org.junit.Test)77 FreeStyleProject (hudson.model.FreeStyleProject)69 ParametersAction (hudson.model.ParametersAction)45 StringParameterValue (hudson.model.StringParameterValue)44 FreeStyleBuild (hudson.model.FreeStyleBuild)43 Issue (org.jvnet.hudson.test.Issue)26 ParameterDefinition (hudson.model.ParameterDefinition)24 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)16 FileWriteBuilder (hudson.plugins.copyartifact.testutils.FileWriteBuilder)15 ArtifactArchiver (hudson.tasks.ArtifactArchiver)15 Shell (hudson.tasks.Shell)15 Cause (hudson.model.Cause)12 ArrayList (java.util.ArrayList)11 CIMessageNotifier (com.redhat.jenkins.plugins.ci.CIMessageNotifier)10 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)10 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)9 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)9 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)9