use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class ModificationBuildCauseTest method shouldReturnBuildCauseMessage.
@Test
public void shouldReturnBuildCauseMessage() {
MaterialRevisions revisions = new MaterialRevisions();
Modification modification = new Modification(new Date(), "pipelineName/123/stageName/1", "MOCK_LABEL-12", null);
revisions.addRevision(new DependencyMaterial(new CaseInsensitiveString("cruise"), new CaseInsensitiveString("dev")), modification);
BuildCause modificationBuildCause = BuildCause.createWithModifications(revisions, "");
String message = modificationBuildCause.getBuildCauseMessage();
assertThat(message, containsString("triggered by pipelineName/123/stageName/1"));
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class PipelineHistoryMother method singlePipeline.
public static PipelineInstanceModel singlePipeline(String pipelineName, StageInstanceModels stages, Date modifiedDate) {
BuildCause manualForced = BuildCause.createManualForced(new MaterialRevisions(new MaterialRevision(MaterialsMother.hgMaterial(), new Modification(modifiedDate, "abc", "MOCK_LABEL-12", null))), Username.ANONYMOUS);
PipelineInstanceModel model = PipelineInstanceModel.createPipeline(pipelineName, -1, "1", manualForced, stages);
model.setCounter(1);
return model;
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class BuildWorkEnvironmentVariablesTest method createAssignment.
private BuildAssignment createAssignment() {
JobPlan plan = new DefaultJobPlan(new Resources(), new ArtifactPlans(), new ArtifactPropertiesGenerators(), -1, new JobIdentifier(PIPELINE_NAME, 1, "1", STAGE_NAME, "1", JOB_NAME, 123L), null, new EnvironmentVariablesConfig(), new EnvironmentVariablesConfig(), null);
MaterialRevisions materialRevisions = materialRevisions();
BuildCause buildCause = BuildCause.createWithModifications(materialRevisions, TRIGGERED_BY_USER);
List<Builder> builders = new ArrayList<>();
builders.add(new CommandBuilder("ant", "", dir, new RunIfConfigs(), new NullBuilder(), ""));
return BuildAssignment.create(plan, buildCause, builders, dir);
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class BuildCauseProducerService method newProduceBuildCause.
ServerHealthState newProduceBuildCause(PipelineConfig pipelineConfig, BuildType buildType, ScheduleOptions scheduleOptions, ServerHealthStateOperationResult result, long trackingId) {
buildType.canProduce(pipelineConfig, schedulingChecker, serverHealthService, result);
if (!result.canContinue()) {
return result.getServerHealthState();
}
String pipelineName = CaseInsensitiveString.str(pipelineConfig.name());
if (LOGGER.isDebugEnabled()) {
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: " + pipelineName + ". Possible Reasons: (1) Upstream pipelines have not been built yet." + " (2) Materials do not match between configuration and build-cause.");
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 [" + pipelineName + "] not modified");
buildCause = buildType.onEmptyModifications(pipelineConfig, latestRevisions);
} else {
LOGGER.debug("Repository for [" + pipelineName + "] modified; scheduling...");
buildCause = buildType.onModifications(revisions, materialConfigurationChanged, original);
}
}
}
if (buildCause != null) {
buildCause.addOverriddenVariables(scheduleOptions.getVariables());
updateChangedRevisions(pipelineConfig.name(), buildCause);
}
if (isGoodReasonToSchedule(pipelineConfig, buildCause, buildType, materialConfigurationChanged)) {
pipelineScheduleQueue.schedule(pipelineName, buildCause);
schedulingPerformanceLogger.sendingPipelineToTheToBeScheduledQueue(trackingId, pipelineName);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("scheduling pipeline %s with build-cause %s; config origin %s", 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.";
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(message, ncure);
}
return showError(pipelineName, message, ncure.getMessage());
} catch (NoModificationsPresentForDependentMaterialException e) {
if (LOGGER.isDebugEnabled()) {
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);
return showError(pipelineName, message, e.getMessage());
}
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class BuildWorkArtifactUploadingTest method createAssignment.
private BuildAssignment createAssignment(ArtifactPlans artifactPlans, String[] fileToCreate) {
MaterialRevisions materialRevisions = materialRevisions();
BuildCause buildCause = BuildCause.createWithModifications(materialRevisions, "");
List<Builder> builders = new ArrayList<>();
builders.add(new CreateFileBuilder(fileToCreate));
DefaultJobPlan plan = new DefaultJobPlan(new Resources(), artifactPlans, new ArtifactPropertiesGenerators(), -1, new JobIdentifier(PIPELINE_NAME, -2, "1", STAGE_NAME, "1", JOB_NAME), null, new EnvironmentVariablesConfig(), new EnvironmentVariablesConfig(), null);
return BuildAssignment.create(plan, buildCause, builders, buildWorkingDirectory);
}
Aggregations