use of com.thoughtworks.go.config.JobConfig in project gocd by gocd.
the class BuildWorkTest method getWork.
private static Work getWork(String jobXml, String pipelineName, boolean fetchMaterials, boolean cleanWorkingDir) throws Exception {
CruiseConfig cruiseConfig = new MagicalGoConfigXmlLoader(new ConfigCache(), ConfigElementImplementationRegistryMother.withNoPlugins()).loadConfigHolder(FileUtil.readToEnd(IOUtils.toInputStream(ConfigFileFixture.withJob(jobXml, pipelineName)))).config;
JobConfig jobConfig = cruiseConfig.jobConfigByName(pipelineName, STAGE_NAME, JOB_PLAN_NAME, true);
JobPlan jobPlan = JobInstanceMother.createJobPlan(jobConfig, new JobIdentifier(pipelineName, -2, PIPELINE_LABEL, STAGE_NAME, String.valueOf(STAGE_COUNTER), JOB_PLAN_NAME, 0L), new DefaultSchedulingContext());
jobPlan.setFetchMaterials(fetchMaterials);
jobPlan.setCleanWorkingDir(cleanWorkingDir);
final Stage stage = StageMother.custom(STAGE_NAME, new JobInstance(JOB_PLAN_NAME));
BuildCause buildCause = BuildCause.createWithEmptyModifications();
final Pipeline pipeline = new Pipeline(pipelineName, buildCause, stage);
pipeline.setLabel(PIPELINE_LABEL);
List<Builder> builder = builderFactory.buildersForTasks(pipeline, jobConfig.getTasks(), resolver);
BuildAssignment buildAssignment = BuildAssignment.create(jobPlan, BuildCause.createWithEmptyModifications(), builder, pipeline.defaultWorkingFolder());
return new BuildWork(buildAssignment);
}
use of com.thoughtworks.go.config.JobConfig in project gocd by gocd.
the class NullStage method createNullStage.
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;
}
use of com.thoughtworks.go.config.JobConfig in project gocd by gocd.
the class PipelineSqlMapDaoIntegrationTest method shouldNotIncludePipelinesNotUsingUpstreamAsDependencyMaterial_evenIfADependencyRevisionGeneratedOutOfParentPipelineAppearsInPMRrangeForANonDependentPipeline.
@Test
public void shouldNotIncludePipelinesNotUsingUpstreamAsDependencyMaterial_evenIfADependencyRevisionGeneratedOutOfParentPipelineAppearsInPMRrangeForANonDependentPipeline() throws Exception {
// shine -> cruise(depends on shine)
// mingle(not related to shine)
final HgMaterial mingleHg = MaterialsMother.hgMaterial();
PipelineConfig mingle = PipelineConfigMother.pipelineConfig("mingle", mingleHg.config(), new JobConfigs(new JobConfig("run-tests")));
PipelineConfig shine = PipelineMother.twoBuildPlansWithResourcesAndMaterials("shine", "compile");
Pipeline shineInstance = dbHelper.newPipelineWithAllStagesPassed(shine);
PipelineConfig cruise = pipelineConfigFor("cruise", "shine", "compile");
final DependencyMaterial cruiseUpstream = new DependencyMaterial(new CaseInsensitiveString("shine"), new CaseInsensitiveString("compile"));
final Modification cruiseMod = new Modification(new Date(), String.format("shine/%s/compile/%s", shineInstance.getCounter(), shineInstance.getStages().get(0).getCounter()), "shine-1", null);
final Modification mingleFrom = ModificationsMother.oneModifiedFile("1234");
saveRev(mingleHg, mingleFrom);
saveRev(cruiseUpstream, cruiseMod);
final Modification mingleTo = ModificationsMother.oneModifiedFile("abcd");
saveRev(mingleHg, mingleTo);
dbHelper.saveMaterialsWIthPassedStages(instanceFactory.createPipelineInstance(mingle, BuildCause.createManualForced(new MaterialRevisions(new MaterialRevision(mingleHg, mingleTo, mingleFrom)), Username.ANONYMOUS), new DefaultSchedulingContext(GoConstants.DEFAULT_APPROVED_BY), md5, new TimeProvider()));
final Pipeline cruiseInstance = instanceFactory.createPipelineInstance(cruise, BuildCause.createManualForced(new MaterialRevisions(new MaterialRevision(cruiseUpstream, cruiseMod)), Username.ANONYMOUS), new DefaultSchedulingContext(GoConstants.DEFAULT_APPROVED_BY), md5, new TimeProvider());
dbHelper.saveMaterialsWIthPassedStages(cruiseInstance);
PipelineDependencyGraphOld dependencyGraph = pipelineDao.pipelineGraphByNameAndCounter("shine", shineInstance.getCounter());
assertPipelineEquals(shineInstance, dependencyGraph.pipeline());
ensureBuildCauseIsLoadedFor(dependencyGraph.pipeline());
PipelineInstanceModels dependencies = dependencyGraph.dependencies();
assertThat(dependencies.size(), is(1));
assertPipelineEquals(cruiseInstance, dependencies.find("cruise"));
}
use of com.thoughtworks.go.config.JobConfig in project gocd by gocd.
the class SingleJobInstance method createRerunInstances.
public void createRerunInstances(JobInstance oldJob, JobInstances jobInstances, SchedulingContext context, StageConfig stageConfig, final Clock clock, InstanceFactory instanceFactory) {
String jobName = oldJob.getName();
JobConfig jobConfig = stageConfig.jobConfigByInstanceName(jobName, true);
if (jobConfig == null) {
throw new CannotRerunJobException(jobName, "Configuration for job doesn't exist.");
}
if (jobConfig.isRunMultipleInstanceType()) {
String runType = "'run multiple instance'";
throw new CannotRerunJobException(jobName, "Run configuration for job has been changed to " + runType + ".");
}
RunOnAllAgents.CounterBasedJobNameGenerator nameGenerator = new RunOnAllAgents.CounterBasedJobNameGenerator(CaseInsensitiveString.str(jobConfig.name()));
JobInstances instances = instanceFactory.createJobInstance(stageConfig.name(), jobConfig, context, clock, nameGenerator);
for (JobInstance instance : instances) {
instance.setRerun(true);
}
jobInstances.addAll(instances);
}
use of com.thoughtworks.go.config.JobConfig in project gocd by gocd.
the class BuildComposerTest method getAssigment.
private static BuildAssignment getAssigment(String jobXml, String pipelineName, boolean fetchMaterials, boolean cleanWorkingDir) throws Exception {
CruiseConfig cruiseConfig = new MagicalGoConfigXmlLoader(new ConfigCache(), ConfigElementImplementationRegistryMother.withNoPlugins()).loadConfigHolder(FileUtil.readToEnd(IOUtils.toInputStream(ConfigFileFixture.withJob(jobXml, pipelineName)))).config;
JobConfig jobConfig = cruiseConfig.jobConfigByName(pipelineName, STAGE_NAME, JOB_PLAN_NAME, true);
JobPlan jobPlan = JobInstanceMother.createJobPlan(jobConfig, new JobIdentifier(pipelineName, -2, PIPELINE_LABEL, STAGE_NAME, String.valueOf(STAGE_COUNTER), JOB_PLAN_NAME, 0L), new DefaultSchedulingContext());
jobPlan.setFetchMaterials(fetchMaterials);
jobPlan.setCleanWorkingDir(cleanWorkingDir);
final Stage stage = StageMother.custom(STAGE_NAME, new JobInstance(JOB_PLAN_NAME));
BuildCause buildCause = BuildCause.createWithEmptyModifications();
final Pipeline pipeline = new Pipeline(pipelineName, buildCause, stage);
pipeline.setLabel(PIPELINE_LABEL);
List<Builder> builder = builderFactory.buildersForTasks(pipeline, jobConfig.getTasks(), resolver);
return BuildAssignment.create(jobPlan, BuildCause.createWithEmptyModifications(), builder, pipeline.defaultWorkingFolder());
}
Aggregations