Search in sources :

Example 76 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class ModificationBuildCauseTest method shouldReturnBuildCauseMessage.

@Test
public void shouldReturnBuildCauseMessage() {
    MaterialRevisions revisions = new MaterialRevisions();
    Modification modification = new Modification(new Date(), "pipelineName/123/stageName/1", "MOCK_LABEL-12", null);
    revisions.addRevision(new DependencyMaterial(new CaseInsensitiveString("cruise"), new CaseInsensitiveString("dev")), modification);
    BuildCause modificationBuildCause = BuildCause.createWithModifications(revisions, "");
    String message = modificationBuildCause.getBuildCauseMessage();
    assertThat(message, containsString("triggered by pipelineName/123/stageName/1"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 77 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class PipelineHistoryMother method singlePipeline.

public static PipelineInstanceModel singlePipeline(String pipelineName, StageInstanceModels stages, Date modifiedDate) {
    BuildCause manualForced = BuildCause.createManualForced(new MaterialRevisions(new MaterialRevision(MaterialsMother.hgMaterial(), new Modification(modifiedDate, "abc", "MOCK_LABEL-12", null))), Username.ANONYMOUS);
    PipelineInstanceModel model = PipelineInstanceModel.createPipeline(pipelineName, -1, "1", manualForced, stages);
    model.setCounter(1);
    return model;
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 78 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause 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 79 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class BuildCauseProducerService method newProduceBuildCause.

ServerHealthState newProduceBuildCause(PipelineConfig pipelineConfig, BuildType buildType, ScheduleOptions scheduleOptions, ServerHealthStateOperationResult result, long trackingId) {
    buildType.canProduce(pipelineConfig, schedulingChecker, serverHealthService, result);
    if (!result.canContinue()) {
        return result.getServerHealthState();
    }
    String pipelineName = CaseInsensitiveString.str(pipelineConfig.name());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("start producing build cause:" + pipelineName);
    }
    try {
        MaterialRevisions peggedRevisions = specificMaterialRevisionFactory.create(pipelineName, scheduleOptions.getSpecifiedRevisions());
        BuildCause previousBuild = pipelineScheduleQueue.mostRecentScheduled(pipelineName);
        Materials materials = materialConfigConverter.toMaterials(pipelineConfig.materialConfigs());
        MaterialConfigs expandedMaterialConfigs = materialExpansionService.expandMaterialConfigsForScheduling(pipelineConfig.materialConfigs());
        Materials expandedMaterials = materialConfigConverter.toMaterials(expandedMaterialConfigs);
        BuildCause buildCause = null;
        boolean materialConfigurationChanged = hasConfigChanged(previousBuild, expandedMaterials);
        if (previousBuild.hasNeverRun() || materialConfigurationChanged) {
            LOGGER.debug("Using latest modifications from repository for " + pipelineConfig.name());
            MaterialRevisions revisions = materialChecker.findLatestRevisions(peggedRevisions, materials);
            if (!revisions.isMissingModifications()) {
                buildCause = buildType.onModifications(revisions, materialConfigurationChanged, null);
                if (buildCause != null) {
                    if (!buildCause.materialsMatch(expandedMaterialConfigs)) {
                        LOGGER.warn("Error while scheduling pipeline: " + pipelineName + ". Possible Reasons: (1) Upstream pipelines have not been built yet." + " (2) Materials do not match between configuration and build-cause.");
                        return ServerHealthState.success(HealthStateType.general(HealthStateScope.forPipeline(pipelineName)));
                    }
                }
            }
        } else {
            LOGGER.debug("Checking if materials are different for " + pipelineConfig.name());
            MaterialRevisions latestRevisions = materialChecker.findLatestRevisions(peggedRevisions, materials);
            if (!latestRevisions.isMissingModifications()) {
                MaterialRevisions original = previousBuild.getMaterialRevisions();
                MaterialRevisions revisions = materialChecker.findRevisionsSince(peggedRevisions, expandedMaterials, original, latestRevisions);
                if (!revisions.hasChangedSince(original) || (buildType.shouldCheckWhetherOlderRunsHaveRunWithLatestMaterials() && materialChecker.hasPipelineEverRunWith(pipelineName, latestRevisions))) {
                    LOGGER.debug("Repository for [" + pipelineName + "] not modified");
                    buildCause = buildType.onEmptyModifications(pipelineConfig, latestRevisions);
                } else {
                    LOGGER.debug("Repository for [" + pipelineName + "] modified; scheduling...");
                    buildCause = buildType.onModifications(revisions, materialConfigurationChanged, original);
                }
            }
        }
        if (buildCause != null) {
            buildCause.addOverriddenVariables(scheduleOptions.getVariables());
            updateChangedRevisions(pipelineConfig.name(), buildCause);
        }
        if (isGoodReasonToSchedule(pipelineConfig, buildCause, buildType, materialConfigurationChanged)) {
            pipelineScheduleQueue.schedule(pipelineName, buildCause);
            schedulingPerformanceLogger.sendingPipelineToTheToBeScheduledQueue(trackingId, pipelineName);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(format("scheduling pipeline %s with build-cause %s; config origin %s", pipelineName, buildCause, pipelineConfig.getOrigin()));
            }
        } else {
            buildType.notifyPipelineNotScheduled(pipelineConfig);
        }
        serverHealthService.removeByScope(HealthStateScope.forPipeline(pipelineName));
        LOGGER.debug("finished producing buildcause for " + pipelineName);
        return ServerHealthState.success(HealthStateType.general(HealthStateScope.forPipeline(pipelineName)));
    } catch (NoCompatibleUpstreamRevisionsException ncure) {
        String message = "Error while scheduling pipeline: " + pipelineName + " as no compatible revisions were identified.";
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(message, ncure);
        }
        return showError(pipelineName, message, ncure.getMessage());
    } catch (NoModificationsPresentForDependentMaterialException e) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.error(e.getMessage(), e);
        }
        return ServerHealthState.success(HealthStateType.general(HealthStateScope.forPipeline(pipelineName)));
    } catch (Exception e) {
        String message = "Error while scheduling pipeline: " + pipelineName;
        LOGGER.error(message, e);
        return showError(pipelineName, message, e.getMessage());
    }
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 80 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class BuildWorkArtifactUploadingTest method createAssignment.

private BuildAssignment createAssignment(ArtifactPlans artifactPlans, String[] fileToCreate) {
    MaterialRevisions materialRevisions = materialRevisions();
    BuildCause buildCause = BuildCause.createWithModifications(materialRevisions, "");
    List<Builder> builders = new ArrayList<>();
    builders.add(new CreateFileBuilder(fileToCreate));
    DefaultJobPlan plan = new DefaultJobPlan(new Resources(), artifactPlans, new ArtifactPropertiesGenerators(), -1, new JobIdentifier(PIPELINE_NAME, -2, "1", STAGE_NAME, "1", JOB_NAME), null, new EnvironmentVariablesConfig(), new EnvironmentVariablesConfig(), null);
    return BuildAssignment.create(plan, buildCause, builders, buildWorkingDirectory);
}
Also used : Builder(com.thoughtworks.go.domain.builder.Builder) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder) ArrayList(java.util.ArrayList) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Aggregations

BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)158 Test (org.junit.Test)115 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)33 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)32 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)31 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)31 TimeProvider (com.thoughtworks.go.util.TimeProvider)28 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)21 Modification (com.thoughtworks.go.domain.materials.Modification)21 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)16 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)16 ValueStreamMapPresentationModel (com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel)16 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)14 Date (java.util.Date)14 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)13 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)12 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)11 Username (com.thoughtworks.go.server.domain.Username)10 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)10 Builder (com.thoughtworks.go.domain.builder.Builder)9