private ConfigOrigin pipelineConfigOrigin(CruiseConfig cruiseConfig, final CaseInsensitiveString pipelineName) { PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(pipelineName); if (pipelineConfig == null) return null; return pipelineConfig.getOrigin(); }
public boolean hasSameConfigOrigin(PipelineConfig other) { if (!(isConfigDefinedRemotely())) return false; return this.origin.equals(other.getOrigin()); }
public boolean isPipelineEditable(CaseInsensitiveString pipelineName) { PipelineConfig pipelineConfig; try { pipelineConfig = pipelineConfigNamed(pipelineName); } catch (PipelineNotFoundException e) { return false; } return isOriginLocal(pipelineConfig.getOrigin()); }
private GoDashboardPipeline createGoDashboardPipeline(PipelineConfig pipelineConfig, Permissions permissions, PipelineInstanceModels historyForDashboard, PipelineConfigs group) { PipelineModel pipelineModel = pipelineModelFor(pipelineConfig, historyForDashboard); Optional<TrackingTool> trackingTool = pipelineConfig.getIntegratedTrackingTool(); return new GoDashboardPipeline(pipelineModel, permissions, group.getGroup(), trackingTool.orElse(null), timeStampBasedCounter, pipelineConfig.getOrigin()); }
private void haltIfPipelineIsDefinedRemotely(PipelineConfig existingPipelineConfig) { if (!existingPipelineConfig.isLocal()) { throw haltBecauseOfReason(String.format("Can not operate on pipeline '%s' as it is defined remotely in '%s'.", existingPipelineConfig.name(), existingPipelineConfig.getOrigin().displayName())); } }
@Override public void validate(ValidationContext validationContext) { // each of these references is defined in this.origin for (EnvironmentPipelineConfig pipelineRefConfig : this.pipelines) { ConfigReposConfig configRepos = validationContext.getConfigRepos(); PipelineConfig pipelineConfig = validationContext.getPipelineConfigByName(pipelineRefConfig.getName()); if (pipelineConfig == null) { continue;//other rule will error that we reference unknown pipeline } if (validationContext.shouldCheckConfigRepo()) { if (!configRepos.isReferenceAllowed(this.origin, pipelineConfig.getOrigin())) pipelineRefConfig.addError(EnvironmentPipelineConfig.ORIGIN, String.format("Environment defined in %s cannot reference a pipeline in %s", this.origin, displayNameFor(pipelineConfig.getOrigin()))); } } }
private void validateOrigins(PipelineConfig currentPipeline, ValidationContext validationContext) { for (DependencyMaterialConfig material : filterDependencyMaterials()) { PipelineConfig upstream = validationContext.getPipelineConfigByName(material.getPipelineName()); if (upstream == null) continue; // other rule validates existence of upstream ConfigOrigin myOrigin = currentPipeline.getOrigin(); ConfigOrigin upstreamOrigin = upstream.getOrigin(); if (validationContext.shouldCheckConfigRepo()) { if (!validationContext.getConfigRepos().isReferenceAllowed(myOrigin, upstreamOrigin)) { material.addError(DependencyMaterialConfig.ORIGIN, String.format("Dependency from pipeline defined in %s to pipeline defined in %s is not allowed", displayNameFor(myOrigin), displayNameFor(upstreamOrigin))); } } } }
private WaitForPipelineMaterialUpdate(CaseInsensitiveString pipelineName, BuildType buildType, ScheduleOptions scheduleOptions) { this.pipelineConfig = goConfigService.pipelineConfigNamed(pipelineName); this.buildType = buildType; this.scheduleOptions = scheduleOptions; pendingMaterials = new ConcurrentHashMap<>(); if (this.pipelineConfig.isConfigDefinedRemotely()) { // Then we must update config first and then continue as usual. // it is also possible that config will disappear at update RepoConfigOrigin configRepo = (RepoConfigOrigin) this.pipelineConfig.getOrigin(); MaterialConfig materialConfig = configRepo.getMaterial(); configMaterial = materialConfigConverter.toMaterial(materialConfig); pendingMaterials.putIfAbsent(materialConfig.getFingerprint(), configMaterial); } if (scheduleOptions.shouldPerformMDUBeforeScheduling()) { for (MaterialConfig materialConfig : pipelineConfig.materialConfigs()) { pendingMaterials.putIfAbsent(materialConfig.getFingerprint(), materialConfigConverter.toMaterial(materialConfig)); } } }
public Pipeline createPipeline(final BuildCause buildCause, final PipelineConfig pipelineConfig, final SchedulingContext context, final String md5, final Clock clock) { return (Pipeline) transactionTemplate.execute((TransactionCallback) status -> { Pipeline pipeline = null; if (shouldCancel(buildCause, pipelineConfig.name())) { LOGGER.debug("[Pipeline Schedule] Cancelling scheduling as build cause {} is the same as the most recent schedule", buildCause); cancelSchedule(pipelineConfig.name()); } else { try { Pipeline newPipeline = instanceFactory.createPipelineInstance(pipelineConfig, buildCause, context, md5, clock); pipeline = pipelineService.save(newPipeline); finishSchedule(pipelineConfig.name(), buildCause, pipeline.getBuildCause()); LOGGER.debug("[Pipeline Schedule] Successfully scheduled pipeline {}, buildCause:{}, configOrigin: {}", pipelineConfig.name(), buildCause, pipelineConfig.getOrigin()); } catch (BuildCauseOutOfDateException e) { cancelSchedule(pipelineConfig.name()); LOGGER.info("[Pipeline Schedule] Build cause {} is out of date. Scheduling is cancelled. Go will reschedule this pipeline. configOrigin: {}", buildCause, pipelineConfig.getOrigin()); } } return pipeline; }); }
public boolean pipelineConfigAndMaterialRevisionMatch(PipelineConfig pipelineConfig){ if(!pipelineConfig.isConfigOriginSameAsOneOfMaterials()) { return true; } RepoConfigOrigin repoConfigOrigin = (RepoConfigOrigin)pipelineConfig.getOrigin(); MaterialConfig configAndCodeMaterial = repoConfigOrigin.getMaterial(); //TODO if revision in any of the pipelines match MaterialRevision revision = this.getMaterialRevisions().findRevisionForFingerPrint(configAndCodeMaterial.getFingerprint()); String revisionString = revision.getRevision().getRevision(); if(pipelineConfig.isConfigOriginFromRevision(revisionString)) { return true; } return false; }
@Test public void shouldSetConfigOriginInPipeline_AfterLoadingConfigFile() throws Exception { CruiseConfig cruiseConfig = xmlLoader.loadConfigHolder(CONFIG).config; PipelineConfig pipelineConfig1 = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline1")); assertThat(pipelineConfig1.getOrigin(), is(new FileConfigOrigin())); }
@Test public void shouldSetOriginInPipelines() { PipelineConfig pipe = PipelineConfigMother.pipelineConfig("pipeline1"); PipelineConfigs group = new BasicPipelineConfigs(pipe); group.setOrigins(new FileConfigOrigin()); assertThat(pipe.getOrigin(), is(new FileConfigOrigin())); } @Test
private boolean validateExistenceAndOrigin(PipelineConfig currentPipeline, ValidationContext validationContext) { PipelineConfig srcPipeline = validationContext.getPipelineConfigByName(pipelineName.getAncestorName()); if (srcPipeline == null) { //"ProdDeploy :: deploy :: scp" tries|attempts to fetch artifact from pipeline "not-found" which does not exist. addError(PIPELINE, String.format("\"%s :: %s :: %s\" tries to fetch artifact from pipeline \"%s\" which does not exist." , currentPipeline.name(), validationContext.getStage().name(), validationContext.getJob().name(), pipelineName.getAncestorName())); return true; } else { StageConfig srcStage = srcPipeline.findBy(stage); if (srcStage == null) { addError(STAGE, String.format("\"%s :: %s :: %s\" tries to fetch artifact from stage \"%s :: %s\" which does not exist." , currentPipeline.name(), validationContext.getStage().name(), validationContext.getJob().name(), pipelineName.getAncestorName(), stage)); return true; } else { if (srcStage.jobConfigByInstanceName(CaseInsensitiveString.str(job), true) == null) { addError(JOB, String.format("\"%s :: %s :: %s\" tries to fetch artifact from job \"%s :: %s :: %s\" which does not exist.", currentPipeline.name(), validationContext.getStage().name(), validationContext.getJob().name(), pipelineName.getAncestorName(), stage, job)); return true; } } if (validationContext.shouldCheckConfigRepo()) { if (!validationContext.getConfigRepos().isReferenceAllowed(currentPipeline.getOrigin(), srcPipeline.getOrigin())) { addError(ARTIFACT_ORIGIN, String.format("\"%s :: %s :: %s\" tries to fetch artifact from job \"%s :: %s :: %s\" which is defined in %s - reference is not allowed", currentPipeline.name(), validationContext.getStage().name(), validationContext.getJob().name(), pipelineName.getAncestorName(), stage, job, displayNameFor(srcPipeline.getOrigin()))); return true; } } } return false; }
public void assertPipelineConfigAndMaterialRevisionMatch(PipelineConfig pipelineConfig) { if(!pipelineConfig.isConfigOriginSameAsOneOfMaterials()) { return; } // then config and code revision must both match if(this.trigger.isForced() || this.hasDependencyMaterials()) { // we should not check when manual trigger because of re-runs // and possibility to specify revisions to run with return; } RepoConfigOrigin repoConfigOrigin = (RepoConfigOrigin)pipelineConfig.getOrigin(); MaterialConfig configAndCodeMaterial = repoConfigOrigin.getMaterial(); //TODO if revision in any of the pipelines match MaterialRevision revision = this.getMaterialRevisions().findRevisionForFingerPrint(configAndCodeMaterial.getFingerprint()); String revisionString = revision.getRevision().getRevision(); if(pipelineConfig.isConfigOriginFromRevision(revisionString)) { return; } invalidRevision(repoConfigOrigin.getRevision(),revisionString); }
LOGGER.debug("scheduling pipeline {} with build-cause {}; config origin {}", pipelineName, buildCause, pipelineConfig.getOrigin()); } else { buildType.notifyPipelineNotScheduled(pipelineConfig);
@Test public void shouldSetOriginInPipelines() { pipelines = new BasicPipelineConfigs("group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1")); BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines); PipelineConfig pipe = pipelines.get(0); mainCruiseConfig.setOrigins(new FileConfigOrigin()); assertThat(pipe.getOrigin(), is(new FileConfigOrigin())); }
public static void toJSON(OutputWriter jsonWriter, PipelineConfig pipelineConfig) { jsonWriter.addLinks(linksWriter -> linksWriter .addLink("self", Routes.PipelineConfig.name(pipelineConfig.getName().toString())) .addAbsoluteLink("doc", Routes.PipelineConfig.DOC) .addLink("find", Routes.PipelineConfig.find())); // This is needed for the case when there are no materials defined. Refer to pipeline_config_representer.rb#152 pipelineConfig.errors().addAll(pipelineConfig.materialConfigs().errors()); if (!pipelineConfig.errors().isEmpty()) { jsonWriter.addChild("errors", errorWriter -> { HashMap<String, String> errorMapping = new HashMap<>(); errorMapping.put("labelTemplate", "label_template"); errorMapping.put("params", "parameters"); errorMapping.put("variables", "environment_variables"); errorMapping.put("trackingTool", "tracking_tool"); new ErrorGetter(errorMapping).toJSON(errorWriter, pipelineConfig); }); } jsonWriter.add("label_template", pipelineConfig.getLabelTemplate()); jsonWriter.add("lock_behavior", pipelineConfig.getLockBehavior()); jsonWriter.add("name", pipelineConfig.name()); jsonWriter.add("template", pipelineConfig.getTemplateName()); writeOrigin(jsonWriter, pipelineConfig.getOrigin()); jsonWriter.addChildList("parameters", paramsWriter -> ParamRepresenter.toJSONArray(paramsWriter, pipelineConfig.getParams())); jsonWriter.addChildList("environment_variables", envVarsWriter -> EnvironmentVariableRepresenter.toJSON(envVarsWriter, pipelineConfig.getVariables())); jsonWriter.addChildList("materials", materialsWriter -> MaterialRepresenter.toJSONArray(materialsWriter, pipelineConfig.materialConfigs())); writeStages(jsonWriter, pipelineConfig); writeTrackingTool(jsonWriter, pipelineConfig); writeTimer(jsonWriter, pipelineConfig.getTimer()); }