Search in sources :

Example 1 with NullBuilder

use of com.thoughtworks.go.domain.builder.NullBuilder 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 2 with NullBuilder

use of com.thoughtworks.go.domain.builder.NullBuilder 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 3 with NullBuilder

use of com.thoughtworks.go.domain.builder.NullBuilder in project gocd by gocd.

the class BuildAssignmentTest method createAssignment.

private BuildAssignment createAssignment(EnvironmentVariableContext environmentVariableContext, BuildCause buildCause) {
    JobPlan plan = new DefaultJobPlan(new Resources(), new ArrayList<>(), -1, new JobIdentifier(PIPELINE_NAME, 1, "1", STAGE_NAME, "1", JOB_NAME, 123L), null, new EnvironmentVariables(), new EnvironmentVariables(), null, null);
    List<Builder> builders = new ArrayList<>();
    builders.add(new CommandBuilder("ls", "", null, new RunIfConfigs(), new NullBuilder(), ""));
    return BuildAssignment.create(plan, buildCause, builders, null, 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) CommandBuilder(com.thoughtworks.go.domain.builder.CommandBuilder)

Example 4 with NullBuilder

use of com.thoughtworks.go.domain.builder.NullBuilder in project gocd by gocd.

the class BuildWorkEnvironmentVariablesTest method createAssignment.

private BuildAssignment createAssignment() {
    JobPlan plan = new DefaultJobPlan(new Resources(), new ArtifactPlans(), new ArtifactPropertiesGenerators(), -1, new JobIdentifier(PIPELINE_NAME, 1, "1", STAGE_NAME, "1", JOB_NAME, 123L), null, new EnvironmentVariablesConfig(), new EnvironmentVariablesConfig(), null);
    MaterialRevisions materialRevisions = materialRevisions();
    BuildCause buildCause = BuildCause.createWithModifications(materialRevisions, TRIGGERED_BY_USER);
    List<Builder> builders = new ArrayList<>();
    builders.add(new CommandBuilder("ant", "", dir, new RunIfConfigs(), new NullBuilder(), ""));
    return BuildAssignment.create(plan, buildCause, builders, dir);
}
Also used : CommandBuilder(com.thoughtworks.go.domain.builder.CommandBuilder) Builder(com.thoughtworks.go.domain.builder.Builder) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder) ArrayList(java.util.ArrayList) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) CommandBuilder(com.thoughtworks.go.domain.builder.CommandBuilder)

Example 5 with NullBuilder

use of com.thoughtworks.go.domain.builder.NullBuilder in project gocd by gocd.

the class BuildWorkEnvironmentVariablesTest method getBuildWorkWithP4MaterialRevision.

private BuildWork getBuildWorkWithP4MaterialRevision(P4Material p4Material) {
    pipelineConfig.setMaterialConfigs(new Materials(p4Material).convertToConfigs());
    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 = new MaterialRevisions(new MaterialRevision(p4Material, new Modification("user", "comment", "a@b.com", new Date(), "10")));
    BuildCause buildCause = BuildCause.createWithModifications(materialRevisions, TRIGGERED_BY_USER);
    List<Builder> builders = new ArrayList<>();
    builders.add(new CommandBuilder("ant", "", dir, new RunIfConfigs(), new NullBuilder(), ""));
    BuildAssignment assignment = BuildAssignment.create(plan, buildCause, builders, dir, environmentVariableContext, new ArtifactStores());
    return new BuildWork(assignment, systemEnvironment.consoleLogCharset());
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ArtifactStores(com.thoughtworks.go.config.ArtifactStores) Materials(com.thoughtworks.go.config.materials.Materials) CommandBuilder(com.thoughtworks.go.domain.builder.CommandBuilder) Builder(com.thoughtworks.go.domain.builder.Builder) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder) ArrayList(java.util.ArrayList) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder) Date(java.util.Date) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) CommandBuilder(com.thoughtworks.go.domain.builder.CommandBuilder)

Aggregations

Builder (com.thoughtworks.go.domain.builder.Builder)6 NullBuilder (com.thoughtworks.go.domain.builder.NullBuilder)6 CommandBuilder (com.thoughtworks.go.domain.builder.CommandBuilder)4 ArtifactStores (com.thoughtworks.go.config.ArtifactStores)3 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)3 ArrayList (java.util.ArrayList)3 JobResult (com.thoughtworks.go.domain.JobResult)2 Materials (com.thoughtworks.go.config.materials.Materials)1 BuildLogElement (com.thoughtworks.go.domain.BuildLogElement)1 Modification (com.thoughtworks.go.domain.materials.Modification)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 Date (java.util.Date)1