private ArtifactStore getArtifactStoreFor(FetchPluggableArtifactTask task, JobIdentifier fetchFrom) { final JobConfig job = goConfigService.getCurrentConfig().findJob(fetchFrom.getPipelineName(), fetchFrom.getStageName(), fetchFrom.getBuildName()); final PluggableArtifactConfig artifactConfig = job.artifactConfigs().findByArtifactId(task.getArtifactId()); if (artifactConfig == null) { throw new RuntimeException(format("Pluggable artifact with id `%s` does not exist.", task.getArtifactId())); } final ArtifactStore artifactStore = goConfigService.artifactStores().find(artifactConfig.getStoreId()); if (artifactStore == null) { throw new RuntimeException(format("Artifact store with id `%s` does not exist.", task.getArtifactId())); } return artifactStore; }
@Override protected void validateAttributes(ValidationContext validationContext) { if (StringUtils.isBlank(artifactId)) { errors.add("artifactId", "Artifact Id cannot be blank."); } if (isNotBlank(artifactId) && validationContext.isWithinPipelines()) { final PathFromAncestor pipelineNamePathFromAncestor = getPipelineNamePathFromAncestor(); final PipelineConfig pipelineConfig = validationContext.getPipelineConfigByName(pipelineNamePathFromAncestor.getAncestorName()); final JobConfig jobConfig = pipelineConfig.getStage(getStage()).jobConfigByConfigName(getJob()); final PluggableArtifactConfig pluggableArtifactConfig = jobConfig.artifactConfigs().findByArtifactId(artifactId); if (pluggableArtifactConfig == null) { addError("artifactId", format("Pluggable artifact with id `%s` does not exist in [%s/%s/%s].", artifactId, pipelineNamePathFromAncestor.getAncestorName(), getStage(), getJob())); } } configuration.validateTree(); configuration.validateUniqueness("Fetch pluggable artifact"); }
@Test public void findByArtifactId_shouldReturnPluggableArtifactConfigs() { ArtifactConfigs allConfigs = new ArtifactConfigs(); allConfigs.add(new PluggableArtifactConfig("s3", "cd.go.s3")); allConfigs.add(new PluggableArtifactConfig("docker", "cd.go.docker")); final PluggableArtifactConfig s3 = allConfigs.findByArtifactId("s3"); assertThat(s3, is(new PluggableArtifactConfig("s3", "cd.go.s3"))); }
@Test public void findByArtifactId_shouldReturnNullWhenPluggableArtifactConfigNotExistWithGivenId() { ArtifactConfigs allConfigs = new ArtifactConfigs(); allConfigs.add(new PluggableArtifactConfig("s3", "cd.go.s3")); allConfigs.add(new PluggableArtifactConfig("docker", "cd.go.docker")); final PluggableArtifactConfig s3 = allConfigs.findByArtifactId("foo"); assertNull(s3); } }
public PluggableArtifactConfig getSpecifiedExternalArtifact(CruiseConfig cruiseConfig, BaseCollection<StageConfig> pipelineOrTemplate, FetchPluggableArtifactTask preprocessedTask, boolean isPipeline, CaseInsensitiveString pipelineOrTemplateName) { BaseCollection<StageConfig> dependencyMaterial = null; PluggableArtifactConfig externalArtifact = null; boolean isUpstreamAPipeline = isPipeline; if (preprocessedTask.getPipelineName() == null || CaseInsensitiveString.isBlank(preprocessedTask.getTargetPipelineName()) || preprocessedTask.getTargetPipelineName().equals(pipelineOrTemplateName)) { dependencyMaterial = pipelineOrTemplate; } else { try { dependencyMaterial = cruiseConfig.pipelineConfigByName(preprocessedTask.getTargetPipelineName()); isUpstreamAPipeline = true; } catch (PipelineNotFoundException e) { // ignore } } StageConfig upstreamStage; if (dependencyMaterial != null && !dependencyMaterial.isEmpty()) { if (isUpstreamAPipeline) { upstreamStage = ((PipelineConfig) dependencyMaterial).getStage(preprocessedTask.getStage()); } else { upstreamStage = ((PipelineTemplateConfig) dependencyMaterial).getStage(preprocessedTask.getStage()); } if (upstreamStage != null) { JobConfig jobConfig = upstreamStage.jobConfigByConfigName(preprocessedTask.getJob()); if (jobConfig != null) { externalArtifact = jobConfig.artifactConfigs().findByArtifactId(preprocessedTask.getArtifactId()); } } } return externalArtifact; }