use of com.thoughtworks.go.domain.buildcause.BuildCause 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.domain.buildcause.BuildCause 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.domain.buildcause.BuildCause in project gocd by gocd.
the class FetchTaskBuilder method resolveTargetJob.
private JobIdentifier resolveTargetJob(AbstractFetchTask task, Pipeline currentPipeline, UpstreamPipelineResolver resolver) {
PathFromAncestor pipelineNamePathFromAncestor = task.getPipelineNamePathFromAncestor();
if (pipelineNamePathFromAncestor == null || CaseInsensitiveString.isBlank(pipelineNamePathFromAncestor.getPath()) || CaseInsensitiveString.areEqual(new CaseInsensitiveString(currentPipeline.getName()), pipelineNamePathFromAncestor.getPath())) {
task.setPipelineName(new CaseInsensitiveString(currentPipeline.getName()));
String stageCounter = JobIdentifier.LATEST;
if (currentPipeline.hasStageBeenRun(CaseInsensitiveString.str(task.getStage()))) {
stageCounter = String.valueOf(currentPipeline.findStage(CaseInsensitiveString.str(task.getStage())).getCounter());
}
return new JobIdentifier(new StageIdentifier(currentPipeline.getName(), currentPipeline.getCounter(), currentPipeline.getLabel(), CaseInsensitiveString.str(task.getStage()), stageCounter), CaseInsensitiveString.str(task.getJob()));
} else {
DependencyMaterialRevision revision = null;
if (pipelineNamePathFromAncestor.isAncestor()) {
BuildCause buildCause = currentPipeline.getBuildCause();
for (CaseInsensitiveString parentPipelineName : pipelineNamePathFromAncestor.pathToAncestor()) {
DependencyMaterialRevision dependencyMaterialRevision = dmrForPipeline(parentPipelineName, buildCause);
if (dependencyMaterialRevision == null) {
throw bomb(format("Pipeline [%s] could not fetch artifact [%s]. Unable to resolve revision for [%s] from build cause", currentPipeline.getName(), task, parentPipelineName));
}
buildCause = resolver.buildCauseFor(dependencyMaterialRevision.getPipelineName(), dependencyMaterialRevision.getPipelineCounter());
}
revision = dmrForPipeline(pipelineNamePathFromAncestor.getAncestorName(), buildCause);
if (revision == null) {
throw bomb(format("Pipeline [%s] could not fetch artifact [%s]. Unable to resolve revision for [%s] from build cause", currentPipeline.getName(), task, pipelineNamePathFromAncestor.getAncestorName()));
}
} else {
revision = dmrForPipeline(pipelineNamePathFromAncestor.getPath(), currentPipeline.getBuildCause());
if (revision == null) {
throw bomb(format("Pipeline [%s] tries to fetch artifact from job [%s/%s/%s] " + "which is not a dependency material", currentPipeline.getName(), pipelineNamePathFromAncestor, task.getStage(), task.getJob()));
}
}
String stageCounter = JobIdentifier.LATEST;
if (task.getStage().equals(new CaseInsensitiveString(revision.getStageName()))) {
stageCounter = String.valueOf(revision.getStageCounter());
}
return new JobIdentifier(new StageIdentifier(CaseInsensitiveString.str(pipelineNamePathFromAncestor.getAncestorName()), revision.getPipelineCounter(), revision.getPipelineLabel(), CaseInsensitiveString.str(task.getStage()), stageCounter), CaseInsensitiveString.str(task.getJob()));
}
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class PipelineHistoryMother method pipelineHistory.
public static PipelineInstanceModels pipelineHistory(PipelineConfig pipelineConfig, Date scheduleDate, Date modificationDate, String revision, String committer, String commitMessage, String commiterEmail, String commitedFileName, String dirModified, String label) {
PipelineInstanceModels history = PipelineInstanceModels.createPipelineInstanceModels();
Modification modification = new Modification(committer, commitMessage, commiterEmail, modificationDate, revision);
modification.createModifiedFile(commitedFileName, dirModified, ModifiedAction.added);
MaterialRevisions revisions = new MaterialRevisions();
Material material = new MaterialConfigConverter().toMaterial(pipelineConfig.materialConfigs().first());
material.setId(10);
revisions.addRevision(material, modification);
BuildCause buildCause = BuildCause.createManualForced(revisions, Username.ANONYMOUS);
PipelineInstanceModel item = PipelineInstanceModel.createPipeline(CaseInsensitiveString.str(pipelineConfig.name()), -1, label, buildCause, stageHistory(pipelineConfig, scheduleDate));
item.setCounter(1);
item.setId(1);
item.setComment("build comment");
history.add(item);
return history;
}
use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.
the class ModificationBuildCauseTest method shouldIncludeUserWhoForcedBuildInManualBuildCause.
@Test
public void shouldIncludeUserWhoForcedBuildInManualBuildCause() {
BuildCause cause = BuildCause.createManualForced(null, new Username(new CaseInsensitiveString("Joe Bloggs")));
assertThat(cause.getBuildCauseMessage(), containsString("Forced by Joe Bloggs"));
}
Aggregations