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"));
}
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));
}
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());
}
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());
}
}
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];
}
Aggregations