Search in sources :

Example 41 with Materials

use of com.thoughtworks.go.config.materials.Materials in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldAllowRetriggeringIfThePreviousTriggerFailed.

@Test
public void shouldAllowRetriggeringIfThePreviousTriggerFailed() throws Exception {
    GitMaterialConfig materialConfig = MaterialConfigsMother.gitMaterialConfig();
    PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("pipeline"), new MaterialConfigs(materialConfig));
    Material material = new MaterialConfigConverter().toMaterial(materialConfig);
    buildCauseProducerService.manualSchedulePipeline(Username.CRUISE_TIMER, pipelineConfig.name(), new ScheduleOptions(), errorResult());
    HttpOperationResult result = new HttpOperationResult();
    when(materialConfigConverter.toMaterial(materialConfig)).thenReturn(material);
    when(materialExpansionService.expandMaterialConfigsForScheduling(pipelineConfig.materialConfigs())).thenReturn(pipelineConfig.materialConfigs());
    when(materialConfigConverter.toMaterials(pipelineConfig.materialConfigs())).thenReturn(new Materials(material));
    when(goConfigService.pipelineConfigNamed(pipelineConfig.name())).thenReturn(pipelineConfig);
    buildCauseProducerService.manualSchedulePipeline(Username.CRUISE_TIMER, pipelineConfig.name(), new ScheduleOptions(), result);
    assertThat(result.httpCode(), is(202));
    assertThat(result.fullMessage(), is("Request to schedule pipeline pipeline accepted"));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) Materials(com.thoughtworks.go.config.materials.Materials) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 42 with Materials

use of com.thoughtworks.go.config.materials.Materials in project gocd by gocd.

the class BuildWorkEnvironmentVariablesTest method shouldSetUpEnvironmentContextCorrectly.

@Test
public void shouldSetUpEnvironmentContextCorrectly() throws Exception {
    new SystemEnvironment().setProperty("serviceUrl", "some_random_place");
    Materials materials = new Materials(svnMaterial);
    EnvironmentVariableContext environmentVariableContext = doWorkWithMaterials(materials);
    assertThat(environmentVariableContext.getProperty("GO_REVISION"), is("3"));
    assertThat(environmentVariableContext.getProperty("GO_SERVER_URL"), is("some_random_place"));
    assertThat(environmentVariableContext.getProperty("GO_PIPELINE_NAME"), is(PIPELINE_NAME));
    assertThat(environmentVariableContext.getProperty("GO_PIPELINE_LABEL"), is("1"));
    assertThat(environmentVariableContext.getProperty("GO_STAGE_NAME"), is(STAGE_NAME));
    assertThat(environmentVariableContext.getProperty("GO_STAGE_COUNTER"), is("1"));
    assertThat(environmentVariableContext.getProperty("GO_JOB_NAME"), is(JOB_NAME));
    assertThat(environmentVariableContext.getProperty("GO_TRIGGER_USER"), is(TRIGGERED_BY_USER));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Materials(com.thoughtworks.go.config.materials.Materials) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 43 with Materials

use of com.thoughtworks.go.config.materials.Materials 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)

Example 44 with Materials

use of com.thoughtworks.go.config.materials.Materials in project gocd by gocd.

the class BuildCauseProducerService method newProduceBuildCause.

ServerHealthState newProduceBuildCause(PipelineConfig pipelineConfig, BuildType buildType, ScheduleOptions scheduleOptions, OperationResult result, long trackingId) {
    buildType.canProduce(pipelineConfig, schedulingChecker, serverHealthService, result);
    if (!result.canContinue()) {
        return result.getServerHealthState();
    }
    String pipelineName = CaseInsensitiveString.str(pipelineConfig.name());
    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: {}. Possible Reasons: (1) Upstream pipelines have not been built yet. (2) Materials do not match between configuration and build-cause.", pipelineName);
                        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 [{}] not modified", pipelineName);
                    buildCause = buildType.onEmptyModifications(pipelineConfig, latestRevisions);
                } else {
                    LOGGER.debug("Repository for [{}] modified; scheduling...", pipelineName);
                    buildCause = buildType.onModifications(revisions, materialConfigurationChanged, original);
                }
            }
        }
        if (buildCause != null) {
            buildCause.addOverriddenVariables(EnvironmentVariables.toEnvironmentVariables(scheduleOptions.getVariables()));
            updateChangedRevisions(pipelineConfig.name(), buildCause);
        }
        if (isGoodReasonToSchedule(pipelineConfig, buildCause, buildType, materialConfigurationChanged)) {
            pipelineScheduleQueue.schedule(pipelineName, buildCause);
            schedulingPerformanceLogger.sendingPipelineToTheToBeScheduledQueue(trackingId, pipelineName);
            LOGGER.debug("scheduling pipeline {} with build-cause {}; config origin {}", 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.";
        LOGGER.debug(message, ncure);
        return showError(pipelineName, message, ncure.getMessage());
    } catch (NoModificationsPresentForDependentMaterialException e) {
        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);
        result.unprocessibleEntity(message, e.getMessage() != null ? e.getMessage() : message, HealthStateType.general(HealthStateScope.forPipeline(pipelineName)));
        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 45 with Materials

use of com.thoughtworks.go.config.materials.Materials in project gocd by gocd.

the class PipelineService method getRevisionsBasedOnDependenciesForDebug.

// This is for debugging purposes
public String getRevisionsBasedOnDependenciesForDebug(CaseInsensitiveString pipelineName, final Integer targetIterationCount) {
    CruiseConfig cruiseConfig = goConfigService.getCurrentConfig();
    FanInGraph fanInGraph = new FanInGraph(cruiseConfig, pipelineName, materialRepository, pipelineDao, systemEnvironment, materialConfigConverter);
    final String[] iterationData = { null };
    fanInGraph.setFanInEventListener(new FanInEventListener() {

        @Override
        public void iterationComplete(int iterationCount, List<DependencyFanInNode> dependencyFanInNodes) {
            if (iterationCount == targetIterationCount) {
                iterationData[0] = new GsonBuilder().setExclusionStrategies(getGsonExclusionStrategy()).create().toJson(dependencyFanInNodes);
            }
        }
    });
    PipelineConfig pipelineConfig = goConfigService.pipelineConfigNamed(pipelineName);
    Materials materials = materialConfigConverter.toMaterials(pipelineConfig.materialConfigs());
    MaterialRevisions actualRevisions = new MaterialRevisions();
    for (Material material : materials) {
        actualRevisions.addAll(materialRepository.findLatestModification(material));
    }
    MaterialRevisions materialRevisions = fanInGraph.computeRevisions(actualRevisions, pipelineTimeline);
    if (iterationData[0] == null) {
        iterationData[0] = new GsonBuilder().setExclusionStrategies(getGsonExclusionStrategy()).create().toJson(materialRevisions);
    }
    return iterationData[0];
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GsonBuilder(com.google.gson.GsonBuilder) Materials(com.thoughtworks.go.config.materials.Materials) FanInGraph(com.thoughtworks.go.server.service.dd.FanInGraph) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) DependencyFanInNode(com.thoughtworks.go.server.service.dd.DependencyFanInNode) FanInEventListener(com.thoughtworks.go.server.service.dd.FanInEventListener)

Aggregations

Materials (com.thoughtworks.go.config.materials.Materials)63 Test (org.junit.Test)47 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)27 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)20 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)19 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)17 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)13 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)12 Material (com.thoughtworks.go.domain.materials.Material)11 Modification (com.thoughtworks.go.domain.materials.Modification)11 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)10 TimeProvider (com.thoughtworks.go.util.TimeProvider)10 File (java.io.File)10 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)9 Date (java.util.Date)8 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)7 MaterialRevisionsMatchers.containsModifiedFile (com.thoughtworks.go.config.MaterialRevisionsMatchers.containsModifiedFile)5 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)5 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)5 Stage (com.thoughtworks.go.domain.Stage)5