Search in sources :

Example 36 with GitMaterial

use of com.thoughtworks.go.config.materials.git.GitMaterial 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 37 with GitMaterial

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

the class BuildCauseProducerServiceIntegrationTest method shouldTriggerMDUOfConfigRepoMaterialIfThePipelineIsDefinedRemotelyInAConfigRepo_ManualTriggerOfPipeline_EvenIfMDUOptionIsTurnedOFFInRequest.

@Test
public void shouldTriggerMDUOfConfigRepoMaterialIfThePipelineIsDefinedRemotelyInAConfigRepo_ManualTriggerOfPipeline_EvenIfMDUOptionIsTurnedOFFInRequest() throws Exception {
    ConfigRepoConfig repoConfig = new ConfigRepoConfig(new GitMaterialConfig("url2"), "plugin");
    configHelper.addConfigRepo(repoConfig);
    PartialConfig partialConfig = PartialConfigMother.withPipelineMultipleMaterials("remote_pipeline", new RepoConfigOrigin(repoConfig, "4567"));
    PipelineConfig remotePipeline = partialConfig.getGroups().first().getPipelines().get(0);
    GitMaterial git = u.wf((GitMaterial) new MaterialConfigConverter().toMaterial(remotePipeline.materialConfigs().getGitMaterial()), "git");
    u.checkinInOrder(git, u.d(1), "g1r1");
    SvnMaterial svn = u.wf((SvnMaterial) new MaterialConfigConverter().toMaterial(remotePipeline.materialConfigs().getSvnMaterial()), "svn");
    u.checkinInOrder(svn, u.d(1), "svn1r11");
    GitMaterial configRepoMaterial = u.wf((GitMaterial) new MaterialConfigConverter().toMaterial(repoConfig.getMaterialConfig()), "git");
    u.checkinInOrder(configRepoMaterial, u.d(1), "s1");
    goPartialConfig.onSuccessPartialConfig(repoConfig, partialConfig);
    assertTrue(goConfigService.hasPipelineNamed(remotePipeline.name()));
    scheduleOptions.shouldPerformMDUBeforeScheduling(false);
    service.manualSchedulePipeline(username, remotePipeline.name(), scheduleOptions, result);
    assertThat(result.isSuccess(), is(true));
    assertThat(result.message(), is("Request to schedule pipeline remote_pipeline accepted"));
    assertThat(materialUpdateStatusNotifier.hasListenerFor(remotePipeline), is(true));
    assertMDUPendingForMaterial(remotePipeline, configRepoMaterial);
    assertMDUNotPendingForMaterial(remotePipeline, svn);
    assertMDUNotPendingForMaterial(remotePipeline, git);
    assertThat(triggerMonitor.isAlreadyTriggered(remotePipeline.name().toString()), Is.is(true));
    BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(remotePipeline.name().toString());
    assertNull(buildCause);
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) GoPartialConfig(com.thoughtworks.go.config.GoPartialConfig) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 38 with GitMaterial

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

the class BuildCauseProducerServiceIntegrationTimerTest method pipelineWithTimerShouldRunWithLatestMaterialsWhenItHasBeenForceRunWithOlderMaterials_GivenTimerIsSetToTriggerOnlyForNewMaterials.

@Test
public void pipelineWithTimerShouldRunWithLatestMaterialsWhenItHasBeenForceRunWithOlderMaterials_GivenTimerIsSetToTriggerOnlyForNewMaterials() throws Exception {
    int i = 1;
    String pipelineName = "p1";
    GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder");
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWithTimer(pipelineName, u.timer("* * * * * ? 2000", true), u.m(git1));
    u.checkinFile(git1, "g11", temporaryFolder.newFile("blah_g11"), ModifiedAction.added);
    u.checkinFile(git1, "g12", temporaryFolder.newFile("blah_g12"), ModifiedAction.added);
    Date mduTimeForG11 = u.d(i++);
    u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, mduTimeForG11, "g11");
    u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, u.d(i++), "g12");
    u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, mduTimeForG11, "g11");
    pipelineTimeline.update();
    buildCauseProducerService.timerSchedulePipeline(p1.config, new ServerHealthStateOperationResult());
    assertThat(piplineScheduleQueue.toBeScheduled().size(), is(1));
    assertThat(piplineScheduleQueue.toBeScheduled().get(pipelineName).getMaterialRevisions(), isSameMaterialRevisionsAs(u.mrs(u.mr(git1, false, "g12"))));
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Date(java.util.Date) Test(org.junit.Test)

Example 39 with GitMaterial

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

the class BuildCauseProducerServiceIntegrationTimerTest method pipelineWithTimerShouldNotRerunWhenItHasAlreadyRunWithLatestMaterials_GivenTimerIsSetToTriggerOnlyForNewMaterials.

@Test
public void pipelineWithTimerShouldNotRerunWhenItHasAlreadyRunWithLatestMaterials_GivenTimerIsSetToTriggerOnlyForNewMaterials() throws Exception {
    String pipelineName = "p1";
    GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder1");
    GitMaterial git2 = u.wf(new GitMaterial("git2"), "folder2");
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWithTimer(pipelineName, u.timer("* * * * * ? 2000", true), u.m(git1), u.m(git2));
    u.checkinFile(git1, "g11", temporaryFolder.newFile("blah_g11"), ModifiedAction.added);
    u.checkinFile(git2, "g21", temporaryFolder.newFile("blah_g21"), ModifiedAction.added);
    // Run once with latest, when pipeline schedules due to timer.
    buildCauseProducerService.timerSchedulePipeline(p1.config, new ServerHealthStateOperationResult());
    assertThat(piplineScheduleQueue.toBeScheduled().size(), is(1));
    assertThat(piplineScheduleQueue.toBeScheduled().get(pipelineName).getMaterialRevisions(), isSameMaterialRevisionsAs(u.mrs(u.mr(git1, true, "g11"), u.mr(git2, true, "g21"))));
    BuildCause buildCause = piplineScheduleQueue.toBeScheduled().get(pipelineName);
    piplineScheduleQueue.finishSchedule(pipelineName, buildCause, buildCause);
    try (LogFixture logFixture = logFixtureFor(TimedBuild.class, Level.INFO)) {
        // Timer time comes around again. Will NOT rerun since the new flag (runOnlyOnNewMaterials) is ON.
        buildCauseProducerService.timerSchedulePipeline(p1.config, new ServerHealthStateOperationResult());
        assertThat(piplineScheduleQueue.toBeScheduled().size(), is(0));
        assertThat(logFixture.contains(Level.INFO, "Skipping scheduling of timer-triggered pipeline 'p1' as it has previously run with the latest material(s)."), is(true));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 40 with GitMaterial

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

the class BuildCauseProducerServiceIntegrationTimerTest method pipelineWithTimerShouldRunOnlyWithMaterialsWhichChanged_GivenTimerIsSetToTriggerOnlyForNewMaterials.

@Test
public void pipelineWithTimerShouldRunOnlyWithMaterialsWhichChanged_GivenTimerIsSetToTriggerOnlyForNewMaterials() throws Exception {
    int i = 1;
    String pipelineName = "p1";
    GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder1");
    GitMaterial git2 = u.wf(new GitMaterial("git2"), "folder2");
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("up1", u.m(git1));
    ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWithTimer(pipelineName, u.timer("* * * * * ? 2000", true), u.m(git1), u.m(git2), u.m(p1));
    u.checkinFile(git1, "g11", temporaryFolder.newFile("blah_g11"), ModifiedAction.added);
    u.checkinFile(git2, "g21", temporaryFolder.newFile("blah_g21"), ModifiedAction.added);
    Date mduTimeOfG11 = u.d(i++);
    String p1_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, mduTimeOfG11, "g11");
    pipelineTimeline.update();
    // Run once with latest, when pipeline schedules due to timer.
    buildCauseProducerService.timerSchedulePipeline(p2.config, new ServerHealthStateOperationResult());
    assertThat(piplineScheduleQueue.toBeScheduled().size(), is(1));
    assertThat(piplineScheduleQueue.toBeScheduled().get(pipelineName).getMaterialRevisions(), isSameMaterialRevisionsAs(u.mrs(u.mr(git1, true, "g11"), u.mr(git2, true, "g21"), u.mr(p1, true, p1_1))));
    BuildCause buildCause = piplineScheduleQueue.toBeScheduled().get(pipelineName);
    u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), "g11", "g21", p1_1);
    piplineScheduleQueue.finishSchedule(pipelineName, buildCause, buildCause);
    // Check in to git2 and run pipeline P1 once before the timer time. Then, timer happens. Shows those two materials in "yellow" (changed), on the UI.
    u.checkinFile(git2, "g22", temporaryFolder.newFile("blah_g22"), ModifiedAction.added);
    String p1_2 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, mduTimeOfG11, "g11");
    pipelineTimeline.update();
    try (LogFixture logFixture = logFixtureFor(TimedBuild.class, Level.INFO)) {
        buildCauseProducerService.timerSchedulePipeline(p2.config, new ServerHealthStateOperationResult());
        assertThat(piplineScheduleQueue.toBeScheduled().size(), is(1));
        assertThat(piplineScheduleQueue.toBeScheduled().get(pipelineName).getMaterialRevisions(), isSameMaterialRevisionsAs(u.mrs(u.mr(git1, false, "g11"), u.mr(git2, true, "g22"), u.mr(p1, true, p1_2))));
        assertThat(logFixture.contains(Level.INFO, "Skipping scheduling of timer-triggered pipeline 'p1' as it has previously run with the latest material(s)."), is(false));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Date(java.util.Date) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Aggregations

GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)146 Test (org.junit.Test)137 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)70 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)55 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)33 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)31 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)20 ValueStreamMapPresentationModel (com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel)20 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)19 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)13 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)11 Modification (com.thoughtworks.go.domain.materials.Modification)11 File (java.io.File)11 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)10 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)10 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)10 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)10 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)9 Material (com.thoughtworks.go.domain.materials.Material)8 Materials (com.thoughtworks.go.config.materials.Materials)7