@Override public void accept(JobConfigVisitor visitor) { for (PipelineConfig pipelineConfig : pipelinesFromAllGroups()) { for (StageConfig stageConfig : pipelineConfig) { for (JobConfig jobConfig : stageConfig.allBuildPlans()) { visitor.visit(pipelineConfig, stageConfig, jobConfig); } } } }
@Override public void accept(TaskConfigVisitor visitor) { for (PipelineConfig pipelineConfig : pipelinesFromAllGroups()) { for (StageConfig stageConfig : pipelineConfig) { for (JobConfig jobConfig : stageConfig.allBuildPlans()) { for (Task task : jobConfig.tasks()) { if (!(task instanceof NullTask)) { visitor.visit(pipelineConfig, stageConfig, jobConfig, task); } } } } } }
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; }
public static JobHistory buildHistory(StageConfig stageConfig, Date modificationDate) { JobHistory history = new JobHistory(); for (JobConfig jobConfig : stageConfig.allBuildPlans()) { history.addJob(CaseInsensitiveString.str(jobConfig.name()), JobState.Completed, JobResult.Passed, modificationDate); } return history; }
public JobInstances currentJobsOfStage(String pipelineName, StageConfig stageConfig) { JobInstances jobs = new JobInstances(); for (JobConfig jobConfig : stageConfig.allBuildPlans()) { JobConfigIdentifier jobConfigIdentifier = new JobConfigIdentifier(pipelineName, CaseInsensitiveString.str(stageConfig.name()), CaseInsensitiveString.str(jobConfig.name())); List<JobInstance> found = jobStatusCache.currentJobs(jobConfigIdentifier); if (found.isEmpty()) { jobs.add(new NullJobInstance(CaseInsensitiveString.str(jobConfig.name()))); } else { jobs.addAll(found); } } jobs.sortByName(); return jobs; }
@Test public void shouldLoadStageFromXmlPartial() throws Exception { String stageXmlPartial = "<stage name=\"mingle\">\n" + " <jobs>\n" + " <job name=\"functional\">\n" + " <artifacts>\n" + " <log src=\"artifact1.xml\" dest=\"cruise-output\" />\n" + " </artifacts>\n" + " </job>\n" + " </jobs>\n" + "</stage>\n"; StageConfig stage = xmlLoader.fromXmlPartial(stageXmlPartial, StageConfig.class); assertThat(stage.name(), is(new CaseInsensitiveString("mingle"))); assertThat(stage.allBuildPlans().size(), is(1)); assertThat(stage.jobConfigByInstanceName("functional", true), is(notNullValue())); }
@Test public void shouldSupportCommandWithWhiteSpace() throws Exception { String jobWithCommand = "<job name=\"functional\">\n" + " <tasks>\n" + " <exec command=\"c:\\program files\\cmd.exe\" args=\"arguments\" />\n" + " </tasks>\n" + " </job>\n"; String configWithCommand = withCommand(jobWithCommand); CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(configWithCommand).config; Task task = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline1")).first().allBuildPlans().first().tasks().first(); assertThat(task, is(instanceOf(ExecTask.class))); assertThat(task, is(new ExecTask("c:\\program files\\cmd.exe", "arguments", (String) null))); }
@Test public void shouldWriteJobProperties() throws Exception { String jobXml = "<job name=\"dev\">\n" + " <properties>\n" + " <property name=\"coverage\" src=\"reports/emma.html\" xpath=\"//coverage/class\" />\n" + " <property name=\"prop2\" src=\"test.xml\" xpath=\"//value\" />\n" + " </properties>\n" + "</job>"; CruiseConfig config = loader.loadConfigHolder(ConfigFileFixture.withJob(jobXml)).configForEdit; JobConfig jobConfig = config.pipelineConfigByName(new CaseInsensitiveString("pipeline1")).get(1).allBuildPlans().first(); assertThat(writer.toXmlPartial(jobConfig), is(jobXml)); }
private StageConfig stageWithJobResource(String resourceName) { StageConfig stage = StageConfigMother.custom("stage", "job"); JobConfigs configs = stage.allBuildPlans(); ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig.setName(resourceName); configs.get(0).resourceConfigs().add(resourceConfig); return stage; } }
private CruiseConfig cruiseConfigWithProperties(ArtifactPropertyConfig... artifactPropertyConfigs) throws Exception { CruiseConfig cruiseConfig = loader.loadConfigHolder(ONE_PIPELINE).configForEdit; JobConfig jobConfig = BuildPlanMother.withArtifactPropertiesGenerator(artifactPropertyConfigs); cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline1")).first().allBuildPlans().add(jobConfig); return cruiseConfig; }
private JobConfig loadJobConfig(String jobXml) throws Exception { CruiseConfig config = loader.loadConfigHolder(ConfigFileFixture.withJob(jobXml)).configForEdit; return config.pipelineConfigByName(new CaseInsensitiveString("pipeline1")).first().allBuildPlans().first(); }
@Test public void shouldLoadJobProperties() throws Exception { String jobXml = "<job name=\"dev\">\n" + " <properties>\n" + " <property name=\"coverage\" src=\"reports/emma.html\" xpath=\"//coverage/class\" />\n" + " <property name=\"prop2\" src=\"test.xml\" xpath=\"//value\" />\n" + " </properties>\n" + "</job>"; CruiseConfig config = loader.loadConfigHolder(ConfigFileFixture.withJob(jobXml)).configForEdit; JobConfig jobConfig = config.pipelineConfigByName(new CaseInsensitiveString("pipeline1")).get(1).allBuildPlans().first(); assertThat(jobConfig.getProperties().first(), is(new ArtifactPropertyConfig("coverage", "reports/emma.html", "//coverage/class"))); assertThat(jobConfig.getProperties().get(1), is(new ArtifactPropertyConfig("prop2", "test.xml", "//value"))); }
assertThat(stage1.allBuildPlans().size(), is(1)); assertThat("Should require approval", stage1.requiresApproval(), is(true)); AdminsConfig admins = stage1.getApproval().getAuthConfig();