Search in sources :

Example 1 with CommandInterpreter

use of hudson.tasks.CommandInterpreter 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 2 with CommandInterpreter

use of hudson.tasks.CommandInterpreter in project jenkins by jenkinsci.

the class LauncherTest method correctlyExpandEnvVars.

@Issue("JENKINS-19488")
@Test
public void correctlyExpandEnvVars() throws Exception {
    FreeStyleProject project = rule.createFreeStyleProject();
    project.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("A", "aaa"), new StringParameterDefinition("C", "ccc"), new StringParameterDefinition("B", "$A$C")));
    final CommandInterpreter script = Functions.isWindows() ? new BatchFile("echo %A% %B% %C%") : new Shell("echo $A $B $C");
    project.getBuildersList().add(script);
    FreeStyleBuild build = rule.buildAndAssertSuccess(project);
    rule.assertLogContains("aaa aaaccc ccc", build);
}
Also used : BatchFile(hudson.tasks.BatchFile) Shell(hudson.tasks.Shell) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) 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 3 with CommandInterpreter

use of hudson.tasks.CommandInterpreter in project postbuildscript-plugin by jenkinsci.

the class CommandExecutor method buildArguments.

private List<String> buildArguments(Command command, String scriptContent) throws IOException, InterruptedException {
    CommandInterpreter interpreter = createInterpreter(scriptContent);
    FilePath scriptFile = interpreter.createScriptFile(workspace);
    List<String> args = new ArrayList<>(Arrays.asList(interpreter.buildCommandLine(scriptFile)));
    args.addAll(command.getParameters());
    return args;
}
Also used : FilePath(hudson.FilePath) ArrayList(java.util.ArrayList) CommandInterpreter(hudson.tasks.CommandInterpreter)

Aggregations

CommandInterpreter (hudson.tasks.CommandInterpreter)3 FreeStyleBuild (hudson.model.FreeStyleBuild)2 FreeStyleProject (hudson.model.FreeStyleProject)2 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)2 StringParameterDefinition (hudson.model.StringParameterDefinition)2 BatchFile (hudson.tasks.BatchFile)2 Shell (hudson.tasks.Shell)2 Test (org.junit.Test)2 Issue (org.jvnet.hudson.test.Issue)2 SmokeTest (org.jvnet.hudson.test.SmokeTest)2 FilePath (hudson.FilePath)1 Slave (hudson.model.Slave)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.emptyString (org.hamcrest.Matchers.emptyString)1