use of com.thoughtworks.go.config.StageConfig in project gocd by gocd.
the class DefaultSchedulingContextTest method shouldSetEnvironmentVariablesOnSchedulingContext.
@Test
public void shouldSetEnvironmentVariablesOnSchedulingContext() throws Exception {
EnvironmentVariablesConfig existing = new EnvironmentVariablesConfig();
existing.add("firstVar", "firstVal");
existing.add("overriddenVar", "originalVal");
SchedulingContext schedulingContext = new DefaultSchedulingContext();
schedulingContext = schedulingContext.overrideEnvironmentVariables(existing);
EnvironmentVariablesConfig stageLevel = new EnvironmentVariablesConfig();
stageLevel.add("stageVar", "stageVal");
stageLevel.add("overriddenVar", "overriddenVal");
StageConfig config = StageConfigMother.custom("test", Approval.automaticApproval());
config.setVariables(stageLevel);
ReflectionUtil.setField(schedulingContext, "rerun", true);
SchedulingContext context = schedulingContext.overrideEnvironmentVariables(config.getVariables());
assertThat(context.isRerun(), is(true));
EnvironmentVariablesConfig environmentVariablesUsed = context.getEnvironmentVariablesConfig();
assertThat(environmentVariablesUsed.size(), is(3));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("firstVar", "firstVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("overriddenVar", "overriddenVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("stageVar", "stageVal")));
}
use of com.thoughtworks.go.config.StageConfig in project gocd by gocd.
the class UnrunStagesPopulator method populateConfiguredStages.
private void populateConfiguredStages(Node node, PipelineConfig pipelineConfig) {
UnrunPipelineRevision unrunPipelineRevision = new UnrunPipelineRevision(node.getName());
for (StageConfig stageConfig : pipelineConfig) {
unrunPipelineRevision.addStage(new NullStage(stageConfig.name().toString()));
}
node.addRevision(unrunPipelineRevision);
}
use of com.thoughtworks.go.config.StageConfig in project gocd by gocd.
the class UnrunStagesPopulator method appendUnrunStages.
private void appendUnrunStages(PipelineConfig pipelineConfig, PipelineRevision pipelineRevision) {
Stages stages = pipelineRevision.getStages();
StageConfig nextStage = pipelineConfig.nextStage(new CaseInsensitiveString(stages.last().getName()));
while (nextStage != null && !stages.hasStage(nextStage.name().toString())) {
pipelineRevision.addStage(new NullStage(nextStage.name().toString()));
nextStage = pipelineConfig.nextStage(nextStage.name());
}
}
use of com.thoughtworks.go.config.StageConfig in project gocd by gocd.
the class MaterialRevisionBuilder method depInstance.
public Tuple depInstance(String pipelineName, int counter, Date modifiedTime, Tuple... buildCause) {
String key = key(pipelineName, counter, modifiedTime);
if (!instanceToRevision.containsKey(key)) {
if (buildCause.length == 0) {
throw new RuntimeException("Cannot create instance without a buildcause. You can retrive it without buildcause once it has been created");
}
DependencyMaterial material = new DependencyMaterial(new CaseInsensitiveString(pipelineName), new CaseInsensitiveString(STAGE_NAME));
DependencyMaterialRevision revision = DependencyMaterialRevision.create(pipelineName, counter, "label", STAGE_NAME, 1);
instanceToRevision.put(key, revision.convert(material, modifiedTime));
final long id = getNextId();
org.mockito.Mockito.when(pipelineDao.findPipelineByNameAndCounter(pipelineName, counter)).thenReturn(pipeline(id));
org.mockito.Mockito.when(materialRepository.findMaterialRevisionsForPipeline(id)).thenReturn(buildCauseOfThisPipeline(buildCause));
}
MaterialRevision materialRevision = instanceToRevision.get(key);
Materials materials = new Materials();
for (MaterialRevision revision : buildCauseOfThisPipeline(buildCause)) {
materials.add(revision.getMaterial());
}
PipelineConfig config = new PipelineConfig(new CaseInsensitiveString(pipelineName), materials.convertToConfigs(), new StageConfig(new CaseInsensitiveString(STAGE_NAME), new JobConfigs()));
return new Tuple(new PipelineConfigDependencyGraph(config, dependencyGraphsFor(buildCause)), materialRevision);
}
use of com.thoughtworks.go.config.StageConfig in project gocd by gocd.
the class StageApprovalAuthorizationTest method shouldAuthorizeIfUserIsInApprovalList.
@Test
public void shouldAuthorizeIfUserIsInApprovalList() throws Exception {
CONFIG_HELPER.addSecurityWithAdminConfig();
StageConfig stage = StageConfigMother.custom("ft", authConfigWithUserJez);
PipelineConfig pipeline = CONFIG_HELPER.addStageToPipeline(PIPELINE_NAME, stage);
assertThat("User jez should have permission on ft stage", securityService.hasOperatePermissionForStage(CaseInsensitiveString.str(pipeline.name()), CaseInsensitiveString.str(stage.name()), "jez"), is(true));
}
Aggregations