public void addMingleConfigToPipeline(String pipelineName, MingleConfig mingleConfig) { CruiseConfig config = loadForEdit(); PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); pipelineConfig.setMingleConfig(mingleConfig); writeConfigFile(config); }
GoAcl readAclBy(String pipelineName, String stageName) { PipelineConfig pipelineConfig = pipelineConfigNamed(new CaseInsensitiveString(pipelineName)); StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(stageName)); AdminsConfig adminsConfig = stageConfig.getApproval().getAuthConfig(); List<CaseInsensitiveString> users = getAuthorizedUsers(adminsConfig); return new GoAcl(users); }
public void addParamToPipeline(String pipeline, String paramName, String paramValue) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipeline)); pipelineConfig.addParam(new ParamConfig(paramName, paramValue)); writeConfigFile(cruiseConfig); }
@Test public void shouldScheduleIfAgentMatchingResources() throws Exception { JobConfig plan = evolveConfig .findBy(new CaseInsensitiveString(STAGE_NAME)) .jobConfigByInstanceName("unit", true); plan.addResource("some-resource"); scheduleHelper.schedule(evolveConfig, modifySomeFiles(evolveConfig), DEFAULT_APPROVED_BY); AgentConfig agentConfig = AgentMother.localAgent(); agentConfig.addResource(new Resource("some-resource")); buildAssignmentService.onTimer(); Work work = buildAssignmentService.assignWorkToAgent(agent(agentConfig)); assertThat(work, is(not((Work) BuildAssignmentService.NO_WORK))); Pipeline pipeline = pipelineDao.mostRecentPipeline(CaseInsensitiveString.str(evolveConfig.name())); JobInstance job = pipeline.findStage(STAGE_NAME).findJob("unit"); JobPlan loadedPlan = jobInstanceDao.loadPlan(job.getId()); assertThat(loadedPlan.getResources(), is((List<Resource>) plan.resources())); assertThat(job.getState(), is(JobState.Assigned)); assertThat(job.getAgentUuid(), is(agentConfig.getUuid())); }
public PipelineConfig addStageToPipeline(String pipelineName, StageConfig stageConfig) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); pipelineConfig.add(stageConfig); writeConfigFile(cruiseConfig); return pipelineConfig; }
public void addEnvironmentVariableToPipeline( String pipelineName, EnvironmentVariablesConfig envVars) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); pipelineConfig.setVariables(envVars); writeConfigFile(cruiseConfig); }
public List<CaseInsensitiveString> pipelines(String group) { PipelineConfigs configs = getCurrentConfig().pipelines(group); List<CaseInsensitiveString> pipelines = new ArrayList<>(); for (PipelineConfig config : configs) { pipelines.add(config.name()); } return pipelines; }
@Test public void shouldReturnIndexOfPipeline() { PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1")); PipelineConfig pipelineConfig = (PipelineConfig) group.get(0).clone(); pipelineConfig.setLabelTemplate("blah"); group.update(group.getGroup(), pipelineConfig, "pipeline1"); assertThat(group.get(0).getLabelTemplate(), is("blah")); }
private void updateApproval(String pipelineName, String ftStage, Approval manualApproval) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); StageConfig config = pipelineConfig.findBy(new CaseInsensitiveString(ftStage)); config.updateApproval(manualApproval); writeConfigFile(cruiseConfig); }
public List<PipelineConfig> downstreamPipelinesOf(String pipelineName) { List<PipelineConfig> dependencies = new ArrayList<>(); for (PipelineConfig config : getAllPipelineConfigs()) { if (config.dependsOn(new CaseInsensitiveString(pipelineName))) { dependencies.add(config); } } return dependencies; }
public PipelineConfig removeMaterialFromPipeline( String pipelineName, MaterialConfig materialConfig) { CruiseConfig config = loadForEdit(); PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); pipelineConfig.removeMaterialConfig(materialConfig); writeConfigFile(config); return pipelineConfig; }
public StageConfig removeStage(String pipelineName, String stageName) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(stageName)); pipelineConfig.remove(stageConfig); writeConfigFile(cruiseConfig); return stageConfig; }
public void removeJob(String pipelineName, String stageName, String jobName) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(stageName)); JobConfig job = stageConfig.getJobs().getJob(new CaseInsensitiveString(jobName)); stageConfig.getJobs().remove(job); writeConfigFile(cruiseConfig); }
public void addEnvironmentVariableToJob( String pipelineName, String stageName, String jobName, EnvironmentVariablesConfig envVars) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(stageName)); JobConfig jobConfig = stageConfig.jobConfigByConfigName(new CaseInsensitiveString(jobName)); jobConfig.setVariables(envVars); writeConfigFile(cruiseConfig); }
private PipelineConfig replaceMaterialConfigForPipeline( String pipelinename, MaterialConfigs materialConfigs) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelinename)); pipelineConfig.setMaterialConfigs(materialConfigs); writeConfigFile(cruiseConfig); return pipelineConfig; }
public PipelineConfig addMaterialToPipeline(String pipelineName, MaterialConfig materialConfig) { CruiseConfig config = loadForEdit(); PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); for (MaterialConfig materialConfig1 : new MaterialConfig[] {materialConfig}) { pipelineConfig.addMaterialConfig(materialConfig1); } writeConfigFile(config); return pipelineConfig; }
public void setRunMultipleInstance( String pipelineName, String stageName, String jobName, Integer runInstanceCount) { CruiseConfig config = loadForEdit(); PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); pipelineConfig .findBy(new CaseInsensitiveString(stageName)) .jobConfigByInstanceName(jobName, true) .setRunInstanceCount(runInstanceCount); writeConfigFile(config); }
private List<String> invertSelections(List<String> selectedPipelines) { List<String> unselectedPipelines = new ArrayList<>(); List<PipelineConfig> pipelineConfigList = cruiseConfig().getAllPipelineConfigs(); for (PipelineConfig pipelineConfig : pipelineConfigList) { String pipelineName = CaseInsensitiveString.str(pipelineConfig.name()); if (!selectedPipelines.contains(pipelineName)) { unselectedPipelines.add(pipelineName); } } return unselectedPipelines; }
public void setRunOnAllAgents( String pipelineName, String stageName, String jobName, boolean runOnAllAgents) { CruiseConfig config = loadForEdit(); PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); pipelineConfig .findBy(new CaseInsensitiveString(stageName)) .jobConfigByInstanceName(jobName, true) .setRunOnAllAgents(runOnAllAgents); writeConfigFile(config); }
public PipelineConfig addPipelineWithTemplate( String groupName, String pipelineName, String templateName) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = new PipelineConfig( new CaseInsensitiveString(pipelineName), MaterialConfigsMother.mockMaterialConfigs("svn:///user:pass@tmp/foo")); pipelineConfig.setTemplateName(new CaseInsensitiveString(templateName)); cruiseConfig.findGroup(groupName).add(pipelineConfig); writeConfigFile(cruiseConfig); return pipelineConfig; }
private StageConfig pushJobIntoStage( String pipelineName, String stageName, JobConfig jobConfig, boolean clearExistingJobs) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(stageName)); if (clearExistingJobs) { stageConfig.allBuildPlans().clear(); } stageConfig.allBuildPlans().add(jobConfig); writeConfigFile(cruiseConfig); return stageConfig; }
public void addResourcesFor( String pipelineName, String stageName, String jobName, String... resources) { CruiseConfig config = loadForEdit(); PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString(pipelineName)); for (String resource : resources) { pipelineConfig .findBy(new CaseInsensitiveString(stageName)) .jobConfigByConfigName(new CaseInsensitiveString(jobName)) .addResource(resource); } writeConfigFile(config); }
public PipelineConfig addPipeline( String pipelineName, String stageName, MaterialConfig materialConfig, TrackingTool trackingTool, String... jobs) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = goConfigMother.addPipeline( cruiseConfig, pipelineName, stageName, new MaterialConfigs(materialConfig), jobs); pipelineConfig.setTrackingTool(trackingTool); writeConfigFile(cruiseConfig); return pipelineConfig; }
@Test public void shouldGetGroupWithTemplatesAsXml() throws Exception { configHelper.addTemplate("template-1", "dev"); configHelper.addPipelineWithGroup("group", "pipeline", "dev", "linux"); PipelineConfig pipelineWithTemplate = configHelper.addPipelineWithTemplate("group", "pipeline-with-template", "template-1"); assertThat( pipelineWithTemplate.size(), is(0)); // should not expect mutation of pipeline config passed in assertThat( configHelper .currentConfig() .pipelineConfigByName(new CaseInsensitiveString("pipeline-with-template")) .size(), is(1)); CruiseConfig config = goConfigService.currentCruiseConfig(); PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString("pipeline-with-template")); assertThat("Should not modify the original template", pipelineConfig.size(), is(1)); controller.getGroupAsXmlPartial("group", null, response); String content = "<pipelines group=\"group\">\n" + " <pipeline name=\"pipeline\">\n" + " <materials>\n" + " <svn url=\"svn:///user:pass@tmp/foo\" />\n" + " </materials>\n" + " <stage name=\"dev\">\n" + " <jobs>\n" + " <job name=\"linux\" />\n" + " </jobs>\n" + " </stage>\n" + " </pipeline>\n" + " <pipeline name=\"pipeline-with-template\" template=\"template-1\">\n" + " <materials>\n" + " <svn url=\"svn:///user:pass@tmp/foo\" />\n" + " </materials>\n" + " </pipeline>\n" + "</pipelines>"; assertValidContentAndStatus(SC_OK, "text/xml", content); MockHttpServletResponse postResponse = new MockHttpServletResponse(); controller.postGroupAsXmlPartial("group", content, null, postResponse); config = goConfigService.currentCruiseConfig(); pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString("pipeline-with-template")); assertThat("Should not modify the original template", pipelineConfig.size(), is(1)); }
public PipelineConfig addPipelineWithGroup( String groupName, String pipelineName, MaterialConfigs materialConfigs, MingleConfig mingleConfig, String stageName, String... buildNames) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = goConfigMother.addPipelineWithGroup( cruiseConfig, groupName, pipelineName, materialConfigs, stageName, buildNames); pipelineConfig.setMingleConfig(mingleConfig); writeConfigFile(cruiseConfig); return pipelineConfig; }
public PipelineConfig addPipelineWithGroup( String groupName, String pipelineName, MaterialConfigs materialConfigs, TrackingTool trackingTool, String stageName, String... jobs) { CruiseConfig cruiseConfig = loadForEdit(); PipelineConfig pipelineConfig = goConfigMother.addPipelineWithGroup( cruiseConfig, groupName, pipelineName, materialConfigs, stageName, jobs); pipelineConfig.setTrackingTool(trackingTool); writeConfigFile(cruiseConfig); return pipelineConfig; }
@Test public void shouldUpdateScmConfigurationOfPluggableScmMaterialsOnPipeline() { String jobName = "job-one"; PipelineConfig pipelineConfig = setupPipelineWithScmMaterial("pipeline_with_pluggable_scm_mat", "stage", jobName); final Pipeline previousSuccessfulBuildWithOlderScmConfig = simulateSuccessfulPipelineRun(pipelineConfig); PipelineConfig updatedPipelineConfig = configHelper.updatePipeline( pipelineConfig.name(), new GoConfigFileHelper.Updater<PipelineConfig>() { @Override public void update(PipelineConfig config) { PluggableSCMMaterialConfig materialConfig = (PluggableSCMMaterialConfig) config.materialConfigs().first(); materialConfig .getSCMConfig() .getConfiguration() .getProperty("password") .setConfigurationValue(new ConfigurationValue("new_value")); } }); final long jobId = rerunJob(jobName, pipelineConfig, previousSuccessfulBuildWithOlderScmConfig); Pipeline loadedPipeline = (Pipeline) transactionTemplate.execute( new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { return loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId); } }); MaterialRevisions revisions = loadedPipeline.getBuildCause().getMaterialRevisions(); Configuration updatedConfiguration = ((PluggableSCMMaterial) revisions .findRevisionFor(updatedPipelineConfig.materialConfigs().first()) .getMaterial()) .getScmConfig() .getConfiguration(); assertThat(updatedConfiguration.size(), is(2)); assertThat( updatedConfiguration.getProperty("password").getConfigurationValue(), is(new ConfigurationValue("new_value"))); }
@Test public void shouldReadFolderAndFilterForPluggableSCMMaterialConfig() throws Exception { String xml = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'>\n" + "<scms>\n" + " <scm id='scm-id' name='scm-name'>\n" + " <pluginConfiguration id='plugin-id' version='1.0'/>\n" + " <configuration>\n" + " <property>\n" + " <key>url</key>\n" + " <value>http://go</value>\n" + " </property>\n" + " </configuration>\n" + " </scm>\n" + " </scms>" + "<pipelines group=\"group_name\">\n" + " <pipeline name=\"new_name\">\n" + " <materials>\n" + " <scm ref='scm-id' dest='dest'>\n" + " <filter>\n" + " <ignore pattern=\"x\"/>\n" + " <ignore pattern=\"y\"/>\n" + " </filter>\n" + " </scm>\n" + " </materials>\n" + " <stage name=\"stage_name\">\n" + " <jobs>\n" + " <job name=\"job_name\" />\n" + " </jobs>\n" + " </stage>\n" + " </pipeline>\n" + "</pipelines></cruise>"; GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml); PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("new_name")); PluggableSCMMaterialConfig pluggableSCMMaterialConfig = (PluggableSCMMaterialConfig) pipelineConfig.materialConfigs().get(0); assertThat( pluggableSCMMaterialConfig.getSCMConfig(), is(goConfigHolder.config.getSCMs().get(0))); assertThat(pluggableSCMMaterialConfig.getFolder(), is("dest")); assertThat( pluggableSCMMaterialConfig.filter(), is(new Filter(new IgnoredFiles("x"), new IgnoredFiles("y")))); }
@Test public void shouldValidateThatPipelineNameIsUnique() { PipelineConfig first = PipelineConfigMother.pipelineConfig("first"); PipelineConfig second = PipelineConfigMother.pipelineConfig("second"); PipelineConfigs group = createWithPipelines(first, second); PipelineConfig duplicate = PipelineConfigMother.pipelineConfig("first"); group.addWithoutValidation(duplicate); group.validate(null); assertThat( duplicate.errors().on(PipelineConfig.NAME), is( "You have defined multiple pipelines called 'first'. Pipeline names are case-insensitive and must be unique.")); assertThat( first.errors().on(PipelineConfig.NAME), is( "You have defined multiple pipelines called 'first'. Pipeline names are case-insensitive and must be unique.")); }
private PipelineConfigDependencyGraph findUpstream(PipelineConfig currentPipeline) { List<PipelineConfigDependencyGraph> graphs = new ArrayList<>(); for (CaseInsensitiveString name : currentPipeline.upstreamPipelines()) { PipelineConfig pipelineConfig = getCurrentConfig().pipelineConfigByName(name); graphs.add(findUpstream(pipelineConfig)); } return new PipelineConfigDependencyGraph( currentPipeline, graphs.toArray(new PipelineConfigDependencyGraph[0])); }