Search in sources :

Example 36 with BuildCause

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

the class BuildWorkTest method getWork.

private static Work getWork(String jobXml, String pipelineName, boolean fetchMaterials, boolean cleanWorkingDir) throws Exception {
    CruiseConfig cruiseConfig = new MagicalGoConfigXmlLoader(new ConfigCache(), ConfigElementImplementationRegistryMother.withNoPlugins()).loadConfigHolder(withJob(jobXml, pipelineName)).config;
    JobConfig jobConfig = cruiseConfig.jobConfigByName(pipelineName, STAGE_NAME, JOB_PLAN_NAME, true);
    JobPlan jobPlan = JobInstanceMother.createJobPlan(jobConfig, new JobIdentifier(pipelineName, -2, PIPELINE_LABEL, STAGE_NAME, String.valueOf(STAGE_COUNTER), JOB_PLAN_NAME, 0L), new DefaultSchedulingContext());
    jobPlan.setFetchMaterials(fetchMaterials);
    jobPlan.setCleanWorkingDir(cleanWorkingDir);
    final Stage stage = StageMother.custom(STAGE_NAME, new JobInstance(JOB_PLAN_NAME));
    BuildCause buildCause = BuildCause.createWithEmptyModifications();
    final Pipeline pipeline = new Pipeline(pipelineName, buildCause, stage);
    pipeline.setLabel(PIPELINE_LABEL);
    List<Builder> builder = builderFactory.buildersForTasks(pipeline, jobConfig.getTasks(), resolver);
    BuildAssignment buildAssignment = BuildAssignment.create(jobPlan, BuildCause.createWithEmptyModifications(), builder, pipeline.defaultWorkingFolder(), null, cruiseConfig.getArtifactStores());
    return new BuildWork(buildAssignment, "utf-8");
}
Also used : Builder(com.thoughtworks.go.domain.builder.Builder) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 37 with BuildCause

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

the class PipelineScheduleQueue method mostRecentScheduled.

public BuildCause mostRecentScheduled(String pipelineName) {
    synchronized (mutexForPipelineName(pipelineName)) {
        BuildCause buildCause = mostRecentScheduled.get(pipelineName);
        if (buildCause != null) {
            return buildCause;
        }
        mostRecentScheduled.put(pipelineName, mostRecentScheduledBuildCause(pipelineName));
        return mostRecentScheduled.get(pipelineName);
    }
}
Also used : BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 38 with BuildCause

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldSchedulePipelineWhenManuallyTriggered.

@Test
public void shouldSchedulePipelineWhenManuallyTriggered() throws Exception {
    configTestRepo.addCodeToRepositoryAndPush("a.java", "added code file", "some java code");
    materialUpdateService.updateMaterial(material);
    waitForMaterialNotInProgress();
    final HashMap<String, String> revisions = new HashMap<>();
    final HashMap<String, String> environmentVariables = new HashMap<>();
    buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, Username.ANONYMOUS, new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
    Map<String, BuildCause> afterLoad = scheduleHelper.waitForAnyScheduled(5);
    assertThat(afterLoad.keySet(), hasItem(PIPELINE_NAME));
    BuildCause cause = afterLoad.get(PIPELINE_NAME);
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
}
Also used : ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 39 with BuildCause

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldReloadPipelineConfigurationAndUpdateNewMaterialWhenManuallyTriggered.

@Test
public void shouldReloadPipelineConfigurationAndUpdateNewMaterialWhenManuallyTriggered() throws Exception {
    GitTestRepo otherGitRepo = new GitTestRepo(temporaryFolder);
    pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipe1", "build", "test");
    pipelineConfig.materialConfigs().clear();
    materialConfig = hgRepo.createMaterialConfig("dest1");
    materialConfig.setAutoUpdate(true);
    pipelineConfig.materialConfigs().add(materialConfig);
    // new material is added
    GitMaterial gitMaterial = otherGitRepo.createMaterial("dest2");
    gitMaterial.setAutoUpdate(true);
    MaterialConfig otherMaterialConfig = gitMaterial.config();
    otherMaterialConfig.setAutoUpdate(true);
    pipelineConfig.materialConfigs().add(otherMaterialConfig);
    List<Modification> mod = configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
    final HashMap<String, String> revisions = new HashMap<>();
    final HashMap<String, String> environmentVariables = new HashMap<>();
    buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, Username.ANONYMOUS, new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
    cachedGoConfig.throwExceptionIfExists();
    Map<String, BuildCause> afterLoad = scheduleHelper.waitForAnyScheduled(20);
    assertThat(afterLoad.keySet(), hasItem(PIPELINE_NAME));
    BuildCause cause = afterLoad.get(PIPELINE_NAME);
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
    PipelineConfig pipelineConfigAfterSchedule = goConfigService.pipelineConfigNamed(pipelineConfig.name());
    RepoConfigOrigin configOriginAfterSchedule = (RepoConfigOrigin) pipelineConfigAfterSchedule.getOrigin();
    String lastPushedRevision = mod.get(0).getRevision();
    assertThat("revisionOfPipelineConfigOriginShouldMatchLastPushedCommit", configOriginAfterSchedule.getRevision(), is(lastPushedRevision));
    assertThat(pipelineConfig.materialConfigs(), hasItem(otherMaterialConfig));
    assertThat("buildCauseRevisionShouldMatchLastPushedCommit", cause.getMaterialRevisions().latestRevision(), is(lastPushedRevision));
    // update of commited material happened during manual trigger
    MaterialRevisions modificationsInDb = materialRepository.findLatestModification(gitMaterial);
    assertThat(modificationsInDb.latestRevision(), is(otherGitRepo.latestModification().get(0).getRevision()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) HashMap(java.util.HashMap) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.Test)

Example 40 with BuildCause

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldSchedulePipelineWithSameMaterialIn2DestinationsWhenManuallyTriggered_WithSpecifiedRevisions.

@Test
public void shouldSchedulePipelineWithSameMaterialIn2DestinationsWhenManuallyTriggered_WithSpecifiedRevisions() throws Exception {
    pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipe1", "build", "test");
    pipelineConfig.materialConfigs().clear();
    materialConfig = hgRepo.createMaterialConfig("dest1");
    materialConfig.setAutoUpdate(true);
    // new material is added
    MaterialConfig otherMaterialConfig = hgRepo.createMaterialConfig("dest2");
    otherMaterialConfig.setAutoUpdate(true);
    pipelineConfig.materialConfigs().add(materialConfig);
    pipelineConfig.materialConfigs().add(otherMaterialConfig);
    List<Modification> firstBuildModifications = configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
    materialUpdateService.updateMaterial(material);
    waitForMaterialNotInProgress();
    cachedGoConfig.throwExceptionIfExists();
    final HashMap<String, String> revisions = new HashMap<>();
    final HashMap<String, String> environmentVariables = new HashMap<>();
    buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, Username.ANONYMOUS, new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
    cachedGoConfig.throwExceptionIfExists();
    Map<String, BuildCause> afterLoad = scheduleHelper.waitForAnyScheduled(5);
    assertThat(afterLoad.keySet(), hasItem(PIPELINE_NAME));
    BuildCause cause = afterLoad.get(PIPELINE_NAME);
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
    List<Modification> secondBuildModifications = configTestRepo.addCodeToRepositoryAndPush("a.java", "added code file", "some java code");
    materialUpdateService.updateMaterial(material);
    waitForMaterialNotInProgress();
    pipelineScheduleQueue.clear();
    // revision in dest 1 will be older by 1 commit - this is kind of scm-config-consistency violation
    String explicitRevision = firstBuildModifications.get(0).getRevision();
    revisions.put(materialConfig.getPipelineUniqueFingerprint(), explicitRevision);
    buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, new Username(new CaseInsensitiveString("Admin")), new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
    cachedGoConfig.throwExceptionIfExists();
    afterLoad = scheduleHelper.waitForAnyScheduled(5);
    assertThat(afterLoad.keySet(), hasItem(PIPELINE_NAME));
    cause = afterLoad.get(PIPELINE_NAME);
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by Admin"));
    PipelineConfig pipelineConfigAfterSchedule = goConfigService.pipelineConfigNamed(pipelineConfig.name());
    RepoConfigOrigin configOriginAfterSchedule = (RepoConfigOrigin) pipelineConfigAfterSchedule.getOrigin();
    String lastPushedRevision = secondBuildModifications.get(0).getRevision();
    assertThat("revisionOfPipelineConfigOriginShouldMatchLastPushedCommit", configOriginAfterSchedule.getRevision(), is(lastPushedRevision));
    assertThat(pipelineConfigAfterSchedule.materialConfigs(), hasItem(otherMaterialConfig));
    assertThat("buildCauseRevisionShouldMatchSpecifiedRevision", cause.getMaterialRevisions().latestRevision(), is(explicitRevision));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) Username(com.thoughtworks.go.server.domain.Username) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.Test)

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