public StageConfig previousStage(final CaseInsensitiveString stageName) { StageConfig lastStageConfig = null; for (StageConfig currentStageConfig : this) { if (currentStageConfig.name().equals(stageName)) { return lastStageConfig; } lastStageConfig = currentStageConfig; } return null; }
public StageConfig findBy(final CaseInsensitiveString stageName) { for (StageConfig stageConfig : this) { if (stageConfig.name().equals(stageName)) { return stageConfig; } } return null; }
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())); } }
public StageConfigurationModels(PipelineConfig pipelineConfig, Map<String, StageIdentifier> mostRecent) { for (StageConfig config : pipelineConfig) { StageInfoAdapter adapter = new StageInfoAdapter(config); if (mostRecent != null) { adapter.setMostRecent(mostRecent.get(CaseInsensitiveString.str(config.name()))); } this.add(adapter); } }
private void populateReferences(List<Map<JobConfigIdentifier, List<PluggableArtifactConfig>>> usedByPipelines, PipelineConfig pipelineConfig) { for (StageConfig stage : pipelineConfig) { JobConfigs jobs = stage.getJobs(); for (JobConfig job : jobs) { final List<PluggableArtifactConfig> artifactConfigs = job.artifactConfigs().findByStoreId(profile.getId()); if (!artifactConfigs.isEmpty()) { usedByPipelines.add(Collections.singletonMap(new JobConfigIdentifier(pipelineConfig.name(), stage.name(), job.name()), artifactConfigs)); } } } } }
private Long findStageIdOf(PipelineConfig pipelineConfig, StageConfig stageConfig) { for (StageIdentity stageIdentity : stageIdentifiers) { if (stageIdentity.getPipelineName().equals(pipelineConfig.name().toString()) && stageIdentity.getStageName().equals(stageConfig.name().toString())) { return stageIdentity.getStageId(); } } return null; } }
private void populateDups(List<JobConfigIdentifier> usedByPipelines, PipelineConfig pipelineConfig) { for (StageConfig stage : pipelineConfig) { JobConfigs jobs = stage.getJobs(); for (JobConfig job : jobs) { String id = profile.getId(); if (id.equals(job.getElasticProfileId())) { usedByPipelines.add(new JobConfigIdentifier(pipelineConfig.name(), stage.name(), job.name())); } } } }
public void updateFutureStagesFrom(PipelineConfig pipelineConfig) { StageInstanceModel lastStage = this.last(); StageConfig nextStage = lastStage == null ? pipelineConfig.getFirstStageConfig() : pipelineConfig.nextStage(new CaseInsensitiveString(lastStage.getName())); while (nextStage != null && !this.hasStage(str(nextStage.name()))) { this.addFutureStage(str(nextStage.name()), !nextStage.requiresApproval()); nextStage = pipelineConfig.nextStage(nextStage.name()); } } }
private void validateWorkingDirectory(ValidationContext validationContext, String stageParentType, Object stageParentName) { if (workingDirectory != null && !FilenameUtil.isNormalizedPathOutsideWorkingDir(workingDirectory)) { errors.add(WORKING_DIRECTORY, String.format("Task of job '%s' in stage '%s' of %s '%s' has path '%s' which is outside the working directory.", validationContext.getJob().name(), validationContext.getStage().name(), stageParentType, stageParentName, workingDirectory)); } }
private StageIdentifier previousStage(Stage stage) { StageIdentifier previousStageIdentifier = null; StageIdentifier currentStageIdentifier = stage.getIdentifier(); String pipelineName = currentStageIdentifier.getPipelineName(); if (isStageAutomaticallyTriggered(stage) || (isManualStage(stage) && !isStageReRun(stage))) { StageConfig previousStage = goConfigService.previousStage(pipelineName, stage.getName()); int latestCounter = stageDao.findLatestStageCounter(stage.getIdentifier().pipelineIdentifier(), previousStage.name().toString()); previousStageIdentifier = new StageIdentifier(currentStageIdentifier.pipelineIdentifier(), previousStage.name().toString(), Integer.toString(latestCounter)); } return previousStageIdentifier; }
@Test public void shouldNotAttemptToEncryptPropertiesIfThereAreNoPluginConfigs() { PipelineConfig pipelineConfig = new PipelineConfig(); StageConfig mockStageConfig = mock(StageConfig.class); pipelineConfig.add(mockStageConfig); JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("job")); when(mockStageConfig.getJobs()).thenReturn(new JobConfigs(jobConfig)); when(mockStageConfig.name()).thenReturn(new CaseInsensitiveString("stage")); pipelineConfig.encryptSecureProperties(new BasicCruiseConfig(), pipelineConfig); verify(mockStageConfig, never()).encryptSecureProperties(eq(new BasicCruiseConfig()), eq(pipelineConfig), ArgumentMatchers.any(StageConfig.class)); }
public void canAutoTriggerProducer(PipelineConfig pipelineConfig, OperationResult operationResult) { String pipelineName = CaseInsensitiveString.str(pipelineConfig.name()); SchedulingChecker checker = buildScheduleCheckers(asList( new PipelineLockChecker(pipelineName, pipelineLockService), new ManualPipelineChecker(pipelineConfig), new PipelinePauseChecker(pipelineName, pipelinePauseService), new StageActiveChecker(pipelineName, CaseInsensitiveString.str(pipelineConfig.getFirstStageConfig().name()), stageService))); checker.check(operationResult); }
private void validateFilePath(ValidationContext validationContext, String path, String propertyName) { if (path == null) { return; } if (!FilenameUtil.isNormalizedPathOutsideWorkingDir(path)) { String parentType = validationContext.isWithinPipelines() ? "pipeline" : "template"; CaseInsensitiveString parentName = validationContext.isWithinPipelines() ? validationContext.getPipeline().name() : validationContext.getTemplate().name(); String message = String.format("Task of job '%s' in stage '%s' of %s '%s' has %s path '%s' which is outside the working directory.", validationContext.getJob().name(), validationContext.getStage().name(), parentType, parentName, propertyName, path); addError(propertyName, message); } }
public ReportingFanInGraph(CruiseConfig cruiseConfig, String root, PipelineDao pipelineDao) { this.cruiseConfig = cruiseConfig; rootName = new CaseInsensitiveString(root); this.pipelineDao = pipelineDao; PipelineConfig target = cruiseConfig.pipelineConfigByName(rootName); this.root = new ReportingDependencyFanInNode(new DependencyMaterialConfig(target.name(), target.get(0).name())); buildGraph(target); }
@Test public void shouldEncryptSecurePropertiesInStagesIfPipelineHasStagesDefined() { PipelineConfig pipelineConfig = new PipelineConfig(); StageConfig mockStageConfig = mock(StageConfig.class); pipelineConfig.add(mockStageConfig); JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("job")); jobConfig.artifactConfigs().add(new PluggableArtifactConfig("foo", "bar")); when(mockStageConfig.getJobs()).thenReturn(new JobConfigs(jobConfig)); when(mockStageConfig.name()).thenReturn(new CaseInsensitiveString("stage")); pipelineConfig.encryptSecureProperties(new BasicCruiseConfig(), pipelineConfig); verify(mockStageConfig).encryptSecureProperties(eq(new BasicCruiseConfig()), eq(pipelineConfig), ArgumentMatchers.any(StageConfig.class)); }
public static NullStage createNullStage(StageConfig stageConfig) { JobInstances nullBuilds = new JobInstances(); for (JobConfig plan : stageConfig.allBuildPlans()) { nullBuilds.add(new NullJobInstance(CaseInsensitiveString.str(plan.name()))); } NullStage nullStage = new NullStage(CaseInsensitiveString.str(stageConfig.name()), nullBuilds); nullStage.setPipelineId(10l); return nullStage; }
private void triggerCurrentStageInNewerPipeline(String pipelineName, Stage currentStage) { // get the most recent passed stage in this collection of pipeline id's StageConfig previousStage = goConfigService.previousStage(pipelineName, currentStage.getName()); Stage mostRecentPassed = stageService.mostRecentPassed(pipelineName, CaseInsensitiveString.str(previousStage.name())); if (mostRecentPassed != null && mostRecentPassed.getPipelineId() > currentStage.getPipelineId()) { Pipeline mostRecentEligiblePipeline = pipelineDao.loadPipeline(mostRecentPassed.getPipelineId()); if (!mostRecentEligiblePipeline.hasStageBeenRun(currentStage.getName())) { triggerNextStageInPipeline(mostRecentEligiblePipeline, mostRecentPassed.getName(), DEFAULT_APPROVED_BY); } } }
@Test public void shouldReturnFalseIfThereIsNextStage() { PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("pipeline"), null, completedStage(), buildingStage()); assertThat(pipelineConfig.hasNextStage(completedStage().name()), is(true)); }
private SchedulingChecker timerTriggerCheckers(PipelineConfig pipelineConfig) { String pipelineName = CaseInsensitiveString.str(pipelineConfig.name()); String stageName = CaseInsensitiveString.str(pipelineConfig.getFirstStageConfig().name()); return new CompositeChecker( new AboutToBeTriggeredChecker(pipelineConfig.name(), triggerMonitor, pipelineScheduleQueue), new PipelinePauseChecker(pipelineName, pipelinePauseService), new StageActiveChecker(pipelineName, stageName, stageService), new PipelineLockChecker(pipelineName, pipelineLockService), diskCheckers()); }
@Test public void shouldFindByName() { PipelineTemplateConfig pipelineTemplateConfig = new PipelineTemplateConfig(new CaseInsensitiveString("pipeline"), StageConfigMother.manualStage("manual"), StageConfigMother.manualStage("manual2")); assertThat(pipelineTemplateConfig.findBy(new CaseInsensitiveString("manuaL2")).name(), is(new CaseInsensitiveString("manual2"))); }