Search in sources :

Example 1 with BuildCommand

use of com.thoughtworks.go.domain.BuildCommand in project gocd by gocd.

the class BuildSessionCancelingTest method cancelTaskShouldBeProcessedBeforeKillChildProcess.

@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { DO_NOT_RUN_ON, WINDOWS })
public void cancelTaskShouldBeProcessedBeforeKillChildProcess() throws InterruptedException {
    final BuildSession buildSession = newBuildSession();
    final BuildCommand printSubProcessCount = exec("/bin/bash", "-c", "pgrep -P " + new JavaSysMon().currentPid() + " | wc -l");
    Thread buildingThread = new Thread(new Runnable() {

        @Override
        public void run() {
            buildSession.build(compose(compose(execSleepScript(50), echo("after sleep")).setOnCancel(printSubProcessCount)));
        }
    });
    buildingThread.start();
    waitUntilSubProcessExists(execSleepScriptProcessCommand(), true);
    assertTrue(buildInfo(), buildSession.cancel(30, TimeUnit.SECONDS));
    waitUntilSubProcessExists(execSleepScriptProcessCommand(), false);
    assertThat(Integer.parseInt(console.lastLine().trim()), greaterThan(0));
    buildingThread.join();
}
Also used : JavaSysMon(com.jezhumble.javasysmon.JavaSysMon) BuildCommand(com.thoughtworks.go.domain.BuildCommand) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 2 with BuildCommand

use of com.thoughtworks.go.domain.BuildCommand in project gocd by gocd.

the class BuildComposer method harvestProperties.

private BuildCommand harvestProperties() {
    List<ArtifactPropertiesGenerator> generators = assignment.getPlan().getPropertyGenerators();
    List<BuildCommand> commands = new ArrayList<>();
    for (ArtifactPropertiesGenerator generator : generators) {
        BuildCommand command = BuildCommand.generateProperty(generator.getName(), generator.getSrc(), generator.getXpath()).setWorkingDirectory(workingDirectory());
        commands.add(command);
    }
    return BuildCommand.compose(reportAction("Start to create properties"), BuildCommand.compose(commands));
}
Also used : ArrayList(java.util.ArrayList) BuildCommand(com.thoughtworks.go.domain.BuildCommand) ArtifactPropertiesGenerator(com.thoughtworks.go.config.ArtifactPropertiesGenerator)

Example 3 with BuildCommand

use of com.thoughtworks.go.domain.BuildCommand in project gocd by gocd.

the class BuildComposer method setupEnvironmentVariables.

private BuildCommand setupEnvironmentVariables() {
    EnvironmentVariableContext context = environmentVariableContext();
    ArrayList<BuildCommand> commands = new ArrayList<>();
    commands.add(export("GO_SERVER_URL"));
    for (String property : context.getPropertyKeys()) {
        commands.add(export(property, context.getProperty(property), context.isPropertySecure(property)));
    }
    return BuildCommand.compose(commands);
}
Also used : ArrayList(java.util.ArrayList) BuildCommand(com.thoughtworks.go.domain.BuildCommand) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext)

Example 4 with BuildCommand

use of com.thoughtworks.go.domain.BuildCommand in project gocd by gocd.

the class TestCommandExecutor method captureSubCommandOutput.

private String captureSubCommandOutput(BuildCommand command, BuildSession buildSession) {
    BuildCommand targetCommand = command.getSubCommands().get(0);
    ConsoleCapture consoleCapture = new ConsoleCapture();
    buildSession.newTestingSession(consoleCapture).processCommand(targetCommand);
    return consoleCapture.captured();
}
Also used : BuildCommand(com.thoughtworks.go.domain.BuildCommand)

Example 5 with BuildCommand

use of com.thoughtworks.go.domain.BuildCommand in project gocd by gocd.

the class CommandBuilder method buildCommand.

@Override
public BuildCommand buildCommand() {
    String[] argsArray = CommandLine.translateCommandLine(args);
    BuildCommand exec = BuildCommand.exec(command, argsArray);
    if (workingDir != null) {
        exec.setWorkingDirectory(workingDir.getPath());
    }
    return exec;
}
Also used : BuildCommand(com.thoughtworks.go.domain.BuildCommand)

Aggregations

BuildCommand (com.thoughtworks.go.domain.BuildCommand)6 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 RunIf (com.googlecode.junit.ext.RunIf)1 JavaSysMon (com.jezhumble.javasysmon.JavaSysMon)1 ArtifactPropertiesGenerator (com.thoughtworks.go.config.ArtifactPropertiesGenerator)1 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)1