Search in sources :

Example 41 with BuildCause

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldReloadPipelineConfigurationWhenManuallyTriggered.

@Test
public void shouldReloadPipelineConfigurationWhenManuallyTriggered() throws Exception {
    // we change configuration of the pipeline by pushing new stage to config repo
    pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipe1", "build", "test", "newStage");
    pipelineConfig.materialConfigs().clear();
    pipelineConfig.materialConfigs().add(materialConfig);
    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());
    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"));
    PipelineConfig pipelineConfigAfterSchedule = goConfigService.pipelineConfigNamed(pipelineConfig.name());
    RepoConfigOrigin configOriginAfterSchedule = (RepoConfigOrigin) pipelineConfigAfterSchedule.getOrigin();
    String lastPushedRevision = mod.get(0).getRevision();
    assertThat("revisionOfPipelineConfigOriginShouldMatchLastPushedCommit", configOriginAfterSchedule.getRevision(), is(lastPushedRevision));
    assertThat("buildCauseRevisionShouldMatchLastPushedCommit", cause.getMaterialRevisions().latestRevision(), is(lastPushedRevision));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) HashMap(java.util.HashMap) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) 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 42 with BuildCause

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldSchedulePipelineRerunWithSpecifiedRevisions.

@Test
public void shouldSchedulePipelineRerunWithSpecifiedRevisions() throws Exception {
    List<Modification> firstBuildModifications = configTestRepo.addCodeToRepositoryAndPush("a.java", "added first code file", "some java code");
    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 second code file", "some java code");
    materialUpdateService.updateMaterial(material);
    waitForMaterialNotInProgress();
    pipelineScheduleQueue.clear();
    // revision will be older by 1 commit -
    // formally this is scm-config-consistency violation but we let this schedule because of manual trigger
    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("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) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.Test)

Example 43 with BuildCause

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldSchedulePipelineWhenConfigAndMaterialRevisionsMismatch_AndManuallyTriggered.

@Test
public // We already let all manual triggers to bypass revision match check
void shouldSchedulePipelineWhenConfigAndMaterialRevisionsMismatch_AndManuallyTriggered() throws Exception {
    // we will use this worker to force material update without updating config
    MaterialUpdateListener byPassWorker = new MaterialUpdateListener(topic, materialDatabaseUpdater, logger, goDiskSpaceMonitor);
    List<Modification> lastPush = configTestRepo.addCodeToRepositoryAndPush("a.java", "added code file", "some java code");
    byPassWorker.onMessage(new MaterialUpdateMessage(material, 123));
    // now db should have been updated, but config is still old
    RepoConfigOrigin configOrigin = (RepoConfigOrigin) goConfigService.pipelineConfigNamed(new CaseInsensitiveString(PIPELINE_NAME)).getOrigin();
    assertThat(configOrigin.getRevision(), is(firstRevisions.latestRevision()));
    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"));
    assertThat("buildCauseRevisionShouldMatchLastPushedCommit", cause.getMaterialRevisions().latestRevision(), is(lastPush.get(0).getRevision()));
}
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) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.Test)

Example 44 with BuildCause

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

the class BuildCauseProducerServiceIntegrationTest method should_produceBuildCause_whenMaterialConfigurationChanges.

@Test
public void should_produceBuildCause_whenMaterialConfigurationChanges() throws Exception {
    SvnMaterial svn1 = SvnMaterial.createSvnMaterialWithMock(repository);
    mingleConfig = configHelper.replaceMaterialForPipeline(MINGLE_PIPELINE_NAME, svn1.config());
    runAndPassWith(svn1, "foo.c", svnRepository);
    scheduleHelper.autoSchedulePipelinesWithRealMaterials(MINGLE_PIPELINE_NAME);
    BuildCause mingleBuildCause = pipelineScheduleQueue.toBeScheduled().get(MINGLE_PIPELINE_NAME);
    assertThat(mingleBuildCause, is(nullValue()));
    svn1.setFolder("another_repo");
    mingleConfig = configHelper.replaceMaterialForPipeline(MINGLE_PIPELINE_NAME, svn1.config());
    scheduleHelper.autoSchedulePipelinesWithRealMaterials(MINGLE_PIPELINE_NAME);
    assertThat(pipelineScheduleQueue.toBeScheduled().keySet(), hasItem(MINGLE_PIPELINE_NAME));
    mingleBuildCause = pipelineScheduleQueue.toBeScheduled().get(MINGLE_PIPELINE_NAME);
    // because material configuration changed, and not actual revisions
    verifyChanged(svn1, mingleBuildCause, false);
}
Also used : SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 45 with BuildCause

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

the class BuildCauseProducerServiceIntegrationTest method shouldUnderstandChangedMaterial_forManual_triggerWithOptions_DoneWithANewRevision.

@Test
public void shouldUnderstandChangedMaterial_forManual_triggerWithOptions_DoneWithANewRevision() throws Exception {
    SvnMaterial svn = SvnMaterial.createSvnMaterialWithMock(repository);
    MaterialRevisions revsAfterFoo = checkinFile(svn, "foo.c", svnRepository);
    String revisionForFingerPrint = revsAfterFoo.findRevisionForFingerPrint(svn.getFingerprint()).getRevision().getRevision();
    scheduleHelper.manuallySchedulePipelineWithRealMaterials(MINGLE_PIPELINE_NAME, new Username(new CaseInsensitiveString("loser")), m(new MaterialConfigConverter().toMaterial(mingleConfig.materialConfigs().get(0)).getPipelineUniqueFingerprint(), revisionForFingerPrint));
    assertThat(pipelineScheduleQueue.toBeScheduled().keySet(), hasItem(MINGLE_PIPELINE_NAME));
    BuildCause bisectAfterBisectBuildCause = pipelineScheduleQueue.toBeScheduled().get(MINGLE_PIPELINE_NAME);
    for (MaterialRevision materialRevision : bisectAfterBisectBuildCause.getMaterialRevisions()) {
        assertThat("material revision " + materialRevision + " should have been considered changed.", materialRevision.isChanged(), is(true));
    }
    assertThat(bisectAfterBisectBuildCause.getMaterialRevisions().getRevisions().size(), is(1));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) 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