use of com.thoughtworks.go.domain.builder.Builder in project gocd by gocd.
the class BuildWorkTest method createBuildWorkWithJobPlan.
private void createBuildWorkWithJobPlan(JobPlan jobPlan) throws Exception {
CruiseConfig cruiseConfig = new MagicalGoConfigXmlLoader(new ConfigCache(), ConfigElementImplementationRegistryMother.withNoPlugins()).loadConfigHolder(FileUtil.readToEnd(IOUtils.toInputStream(ConfigFileFixture.withJob(CMD_NOT_EXIST)))).config;
JobConfig jobConfig = cruiseConfig.jobConfigByName(PIPELINE_NAME, STAGE_NAME, JOB_PLAN_NAME, true);
final Stage stage = StageMother.custom(STAGE_NAME, new JobInstance(JOB_PLAN_NAME));
BuildCause buildCause = BuildCause.createWithEmptyModifications();
final Pipeline pipeline = new Pipeline(PIPELINE_NAME, buildCause, stage);
List<Builder> builder = builderFactory.buildersForTasks(pipeline, jobConfig.getTasks(), resolver);
BuildAssignment buildAssignment = BuildAssignment.create(jobPlan, BuildCause.createWithEmptyModifications(), builder, pipeline.defaultWorkingFolder());
buildWork = new BuildWork(buildAssignment);
}
use of com.thoughtworks.go.domain.builder.Builder in project gocd by gocd.
the class Builders method build.
public JobResult build(EnvironmentVariableContext environmentVariableContext) {
JobResult result = JobResult.Passed;
for (Builder builder : builders) {
if (cancelStarted) {
return JobResult.Cancelled;
}
synchronized (this) {
currentBuilder = builder;
}
BuildLogElement buildLogElement = new BuildLogElement();
try {
builder.build(buildLogElement, RunIfConfig.fromJobResult(result.toLowerCase()), goPublisher, environmentVariableContext, taskExtension);
} catch (Exception e) {
result = JobResult.Failed;
}
buildLog.addContent(buildLogElement.getElement());
}
synchronized (this) {
currentBuilder = new NullBuilder();
}
if (cancelStarted) {
return JobResult.Cancelled;
}
return result;
}
use of com.thoughtworks.go.domain.builder.Builder in project gocd by gocd.
the class Builders method build.
public JobResult build(EnvironmentVariableContext environmentVariableContext, String consoleLogCharset) {
JobResult result = JobResult.Passed;
for (Builder builder : builders) {
if (cancelStarted) {
return JobResult.Cancelled;
}
synchronized (this) {
currentBuilder = builder;
}
if (builder.allowRun(RunIfConfig.fromJobResult(result.toLowerCase()))) {
JobResult taskStatus = JobResult.Passed;
Instant start = Instant.now();
try {
String executeMessage = format("Task: %s", builder.getDescription());
goPublisher.taggedConsumeLineWithPrefix(DefaultGoPublisher.TASK_START, executeMessage);
builder.build(goPublisher, environmentVariableContext, taskExtension, artifactExtension, pluginRequestProcessorRegistry, consoleLogCharset);
} catch (Exception e) {
result = taskStatus = JobResult.Failed;
}
Duration duration = Duration.between(start, Instant.now());
String statusLine = format("Task status: %s (%d ms)", taskStatus.toLowerCase(), duration.toMillis());
if (cancelStarted) {
result = taskStatus = JobResult.Cancelled;
}
String tag;
if (taskStatus.isPassed()) {
tag = DefaultGoPublisher.TASK_PASS;
} else {
if (Builder.UNSET_EXIT_CODE != builder.getExitCode()) {
statusLine = format("%s (exit code: %d)", statusLine, builder.getExitCode());
}
tag = taskStatus.isCancelled() ? DefaultGoPublisher.TASK_CANCELLED : DefaultGoPublisher.TASK_FAIL;
}
goPublisher.taggedConsumeLineWithPrefix(tag, statusLine);
}
}
synchronized (this) {
currentBuilder = new NullBuilder();
}
if (cancelStarted) {
return JobResult.Cancelled;
}
return result;
}
use of com.thoughtworks.go.domain.builder.Builder in project gocd by gocd.
the class BuildAssignmentTest method createAssignment.
private BuildAssignment createAssignment(EnvironmentVariableContext environmentVariableContext) throws IOException {
JobPlan plan = new DefaultJobPlan(new Resources(), new ArrayList<>(), new ArrayList<>(), -1, new JobIdentifier(PIPELINE_NAME, 1, "1", STAGE_NAME, "1", JOB_NAME, 123L), null, new EnvironmentVariables(), new EnvironmentVariables(), null);
MaterialRevisions materialRevisions = materialRevisions();
BuildCause buildCause = BuildCause.createWithModifications(materialRevisions, TRIGGERED_BY_USER);
List<Builder> builders = new ArrayList<>();
builders.add(new CommandBuilder("ls", "", dir, new RunIfConfigs(), new NullBuilder(), ""));
return BuildAssignment.create(plan, buildCause, builders, dir, environmentVariableContext, new ArtifactStores());
}
use of com.thoughtworks.go.domain.builder.Builder in project gocd by gocd.
the class BuildersTest method shouldNotSetAsCurrentBuilderIfNotRun.
@Test
public void shouldNotSetAsCurrentBuilderIfNotRun() throws Exception {
EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
Builder builder = new CommandBuilder("echo", "", new File("."), new RunIfConfigs(FAILED), null, "");
Builders builders = new Builders(Collections.singletonList(builder), null, null, null, null);
builders.setIsCancelled(true);
builders.build(environmentVariableContext, "utf-8");
Builders expected = new Builders(Collections.singletonList(builder), null, null, null, null);
expected.setIsCancelled(true);
assertThat(builders, is(expected));
}
Aggregations