private void validateStagesOfSamePipeline(ValidationContext validationContext, PipelineConfig currentPipeline) { List<StageConfig> validStages = currentPipeline.validStagesForFetchArtifact(currentPipeline, validationContext.getStage().name()); StageConfig matchingStage = validStages.stream().filter(stageConfig -> stageConfig.name().equals(stage)).findFirst().orElse(null); if (matchingStage == null) { addError(STAGE, String.format("\"%s :: %s :: %s\" tries to fetch artifact from its stage \"%s\" which does not complete before the current stage \"%s\"." , currentPipeline.name(), validationContext.getStage().name(), validationContext.getJob().name(), stage, validationContext.getStage().name())); } }
private void validateDependencies(ValidationContext validationContext, PipelineConfig currentPipeline) { DependencyMaterialConfig matchingMaterial = findMatchingDependencyMaterial(currentPipeline, pipelineName.getAncestorName()); PipelineConfig ancestor = validationContext.getPipelineConfigByName(pipelineName.getAncestorName()); if (matchingMaterial == null) { addError(PIPELINE_NAME, String.format("Pipeline \"%s\" tries to fetch artifact from pipeline " + "\"%s\" which is not an upstream pipeline", currentPipeline.name(), pipelineName)); return; } List<StageConfig> validStages = ancestor.validStagesForFetchArtifact(currentPipeline, validationContext.getStage().name()); if (!validStages.contains(ancestor.findBy(stage))) { addStageMayNotCompleteBeforeDownstreamError(currentPipeline, validationContext); } }
@Test public void shouldReturnStagesBeforeCurrentForSelectedPipeline() { PipelineConfig downstream = PipelineConfigMother.createPipelineConfigWithStages("downstream", "s1", "s2"); List<StageConfig> fetchableStages = downstream.validStagesForFetchArtifact(downstream, new CaseInsensitiveString("s2")); assertThat(fetchableStages.size(), is(1)); assertThat(fetchableStages, hasItem(downstream.get(0))); }
@Test public void shouldReturnListOfStageConfigWhichIsApplicableForFetchArtifact() { PipelineConfig superUpstream = PipelineConfigMother.createPipelineConfigWithStages("superUpstream", "s1", "s2", "s3"); PipelineConfig upstream = PipelineConfigMother.createPipelineConfigWithStages("upstream", "s4", "s5", "s6"); upstream.addMaterialConfig(new DependencyMaterialConfig(superUpstream.name(), new CaseInsensitiveString("s2"))); PipelineConfig downstream = PipelineConfigMother.createPipelineConfigWithStages("downstream", "s7"); downstream.addMaterialConfig(new DependencyMaterialConfig(upstream.name(), new CaseInsensitiveString("s5"))); List<StageConfig> fetchableStages = upstream.validStagesForFetchArtifact(downstream, new CaseInsensitiveString("s7")); assertThat(fetchableStages.size(), is(2)); assertThat(fetchableStages, hasItem(upstream.get(0))); assertThat(fetchableStages, hasItem(upstream.get(1))); }