Search in sources :

Example 1 with Builder

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);
}
Also used : ConfigCache(com.thoughtworks.go.config.ConfigCache) Builder(com.thoughtworks.go.domain.builder.Builder) MagicalGoConfigXmlLoader(com.thoughtworks.go.config.MagicalGoConfigXmlLoader) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) JobConfig(com.thoughtworks.go.config.JobConfig) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 2 with Builder

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;
}
Also used : BuildLogElement(com.thoughtworks.go.domain.BuildLogElement) JobResult(com.thoughtworks.go.domain.JobResult) Builder(com.thoughtworks.go.domain.builder.Builder) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder)

Example 3 with Builder

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;
}
Also used : JobResult(com.thoughtworks.go.domain.JobResult) Builder(com.thoughtworks.go.domain.builder.Builder) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder) Instant(java.time.Instant) Duration(java.time.Duration) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder)

Example 4 with Builder

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());
}
Also used : ArtifactStores(com.thoughtworks.go.config.ArtifactStores) CommandBuilder(com.thoughtworks.go.domain.builder.CommandBuilder) Builder(com.thoughtworks.go.domain.builder.Builder) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) CommandBuilder(com.thoughtworks.go.domain.builder.CommandBuilder)

Example 5 with Builder

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));
}
Also used : CommandBuilder(com.thoughtworks.go.domain.builder.CommandBuilder) Builder(com.thoughtworks.go.domain.builder.Builder) StubBuilder(com.thoughtworks.go.domain.builder.StubBuilder) RunIfConfigs(com.thoughtworks.go.domain.RunIfConfigs) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) CommandBuilder(com.thoughtworks.go.domain.builder.CommandBuilder) File(java.io.File) Test(org.junit.Test)

Aggregations

Builder (com.thoughtworks.go.domain.builder.Builder)36 CommandBuilder (com.thoughtworks.go.domain.builder.CommandBuilder)13 Test (org.junit.Test)12 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)9 NullBuilder (com.thoughtworks.go.domain.builder.NullBuilder)8 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)6 File (java.io.File)6 ArrayList (java.util.ArrayList)6 Pipeline (com.thoughtworks.go.domain.Pipeline)5 TasksTest (com.thoughtworks.go.domain.TasksTest)5 FetchArtifactBuilder (com.thoughtworks.go.domain.builder.FetchArtifactBuilder)5 ArtifactStores (com.thoughtworks.go.config.ArtifactStores)4 PluggableTaskBuilder (com.thoughtworks.go.domain.builder.pluggableTask.PluggableTaskBuilder)4 ExecTask (com.thoughtworks.go.config.ExecTask)3 FetchPluggableArtifactBuilder (com.thoughtworks.go.domain.builder.FetchPluggableArtifactBuilder)3 JobResult (com.thoughtworks.go.domain.JobResult)2 RunIfConfigs (com.thoughtworks.go.domain.RunIfConfigs)2 StubGoPublisher (com.thoughtworks.go.domain.StubGoPublisher)2 StubBuilder (com.thoughtworks.go.domain.builder.StubBuilder)2 BuildWork (com.thoughtworks.go.remote.work.BuildWork)2