use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class BuildCauseProducerServiceIntegrationTest method shouldSchedulePipelineWithManualFirstStageWhenManuallyTriggered.
@Test
public void shouldSchedulePipelineWithManualFirstStageWhenManuallyTriggered() throws Exception {
configHelper.configureStageAsManualApproval(MINGLE_PIPELINE_NAME, STAGE_NAME);
svnRepository.checkInOneFile("a.java");
materialDatabaseUpdater.updateMaterial(svnRepository.material());
final HashMap<String, String> revisions = new HashMap<>();
final HashMap<String, String> environmentVariables = new HashMap<>();
buildCauseProducer.manualProduceBuildCauseAndSave(MINGLE_PIPELINE_NAME, Username.ANONYMOUS, new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
Map<String, BuildCause> afterLoad = scheduleHelper.waitForAnyScheduled(5);
assertThat(afterLoad.keySet(), hasItem(MINGLE_PIPELINE_NAME));
BuildCause cause = afterLoad.get(MINGLE_PIPELINE_NAME);
assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
}
use of com.thoughtworks.go.domain.buildcause.BuildCause 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);
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class BuildCauseProducerServiceIntegrationTest method setup.
@Before
public void setup() throws Exception {
diskSpaceSimulator = new DiskSpaceSimulator();
new HgTestRepo("testHgRepo", temporaryFolder);
svnRepository = new SvnTestRepo(temporaryFolder);
dbHelper.onSetUp();
configHelper.onSetUp();
configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile();
repository = new SvnCommand(null, svnRepository.projectRepositoryUrl());
PipelineConfig goParentPipelineConfig = configHelper.addPipeline(GO_PIPELINE_UPSTREAM, STAGE_NAME, new MaterialConfigs(new GitMaterialConfig("foo-bar")), "unit");
goPipelineConfig = configHelper.addPipeline(GO_PIPELINE_NAME, STAGE_NAME, repository, "unit");
svnMaterialRevs = new MaterialRevisions();
svnMaterial = SvnMaterial.createSvnMaterialWithMock(repository);
svnMaterialRevs.addRevision(svnMaterial, svnMaterial.latestModification(null, new ServerSubprocessExecutionContext(goConfigService, new SystemEnvironment())));
final MaterialRevisions materialRevisions = new MaterialRevisions();
SvnMaterial anotherSvnMaterial = SvnMaterial.createSvnMaterialWithMock(repository);
materialRevisions.addRevision(anotherSvnMaterial, anotherSvnMaterial.latestModification(null, subprocessExecutionContext));
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
materialRepository.save(svnMaterialRevs);
}
});
BuildCause buildCause = BuildCause.createWithModifications(svnMaterialRevs, "");
mingleConfig = configHelper.addPipeline(MINGLE_PIPELINE_NAME, STAGE_NAME, repository, new Filter(new IgnoredFiles("**/*.doc")), "unit", "functional");
latestPipeline = PipelineMother.schedule(this.mingleConfig, buildCause);
latestPipeline = pipelineDao.saveWithStages(latestPipeline);
dbHelper.passStage(latestPipeline.getStages().first());
pipelineScheduleQueue.clear();
result = new HttpOperationResult();
scheduleOptions = new ScheduleOptions();
u = new ScheduleTestUtil(transactionTemplate, materialRepository, dbHelper, configHelper);
materialForManualTriggerPipeline = u.wf(new SvnMaterial("svn", "username", "password", false), "folder1");
u.checkinInOrder(materialForManualTriggerPipeline, u.d(1), "s1");
manualTriggerPipeline = configHelper.addPipeline(UUID.randomUUID().toString(), STAGE_NAME, materialForManualTriggerPipeline.config(), "build");
username = Username.ANONYMOUS;
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class BuildCauseProducerServiceIntegrationTest method shouldTriggerMDUOfMaterialsForManualTriggerOfPipelineIfMDUOptionIsTurnedONInRequest.
@Test
public void shouldTriggerMDUOfMaterialsForManualTriggerOfPipelineIfMDUOptionIsTurnedONInRequest() throws Exception {
scheduleOptions.shouldPerformMDUBeforeScheduling(true);
service.manualSchedulePipeline(username, manualTriggerPipeline.name(), scheduleOptions, result);
assertThat(materialUpdateStatusNotifier.hasListenerFor(manualTriggerPipeline), is(true));
assertMDUPendingForMaterial(manualTriggerPipeline, materialForManualTriggerPipeline);
assertThat(result.isSuccess(), is(true));
assertThat(result.message(), is(String.format("Request to schedule pipeline %s accepted", manualTriggerPipeline.name())));
assertThat(triggerMonitor.isAlreadyTriggered(manualTriggerPipeline.name().toString()), Is.is(true));
BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(manualTriggerPipeline.name().toString());
assertNull(buildCause);
}
use of com.thoughtworks.go.domain.buildcause.BuildCause 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));
}
}
Aggregations