use of com.thoughtworks.go.config.EnvironmentVariablesConfig in project gocd by gocd.
the class PipelineScheduleOptionsRepresenter method fromJSON.
public static PipelineScheduleOptions fromJSON(JsonReader jsonReader) {
PipelineScheduleOptions model = new PipelineScheduleOptions();
model.shouldPerformMDUBeforeScheduling(jsonReader.optBoolean("update_materials_before_scheduling").orElse(Boolean.TRUE));
jsonReader.readArrayIfPresent("materials", materials -> {
List<MaterialForScheduling> materialsForScheduling = new ArrayList<>();
materials.forEach(material -> materialsForScheduling.add(MaterialRevisionRepresenter.fromJSON(new JsonReader(material.getAsJsonObject()))));
model.setMaterials(materialsForScheduling);
});
jsonReader.readArrayIfPresent("environment_variables", environmentVariables -> {
EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
environmentVariables.forEach(variable -> variables.add(EnvrionmentVariableRepresenter.fromJSON(new JsonReader(variable.getAsJsonObject()))));
model.setEnvironmentVariables(variables);
});
return model;
}
use of com.thoughtworks.go.config.EnvironmentVariablesConfig 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.EnvironmentVariablesConfig in project gocd by gocd.
the class PipelineScheduleServiceTest method shouldPassEnvironmentLevelEnvironmentVariablesToJobsForNewlyScheduledStage.
@Test
public void shouldPassEnvironmentLevelEnvironmentVariablesToJobsForNewlyScheduledStage() throws Exception {
scheduleAndCompleteInitialPipelines();
Pipeline pipeline = pipelineDao.mostRecentPipeline("go");
Stage stage = scheduleService.scheduleStage(pipeline, "ft", "anonymous", new ScheduleService.NewStageInstanceCreator(goConfigService), new ScheduleService.ExceptioningErrorHandler());
EnvironmentVariablesConfig jobVariables = stage.getJobInstances().first().getPlan().getVariables();
//pipeline, stage, job, env is applied while creating work
assertThat(jobVariables.size(), is(3));
assertThat(jobVariables, hasItem(new EnvironmentVariableConfig("PIPELINE_LVL", "pipeline value")));
assertThat(jobVariables, hasItem(new EnvironmentVariableConfig("STAGE_LVL", "stage value")));
assertThat(jobVariables, hasItem(new EnvironmentVariableConfig("JOB_LVL", "job value")));
}
use of com.thoughtworks.go.config.EnvironmentVariablesConfig in project gocd by gocd.
the class EnvironmentVariablesConfigMother method environmentVariables.
public static EnvironmentVariablesConfig environmentVariables() {
EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
GoCipher goCipher = new GoCipher();
variables.add(new EnvironmentVariableConfig(goCipher, "MULTIPLE_LINES", "multiplelines", true));
variables.add(new EnvironmentVariableConfig(goCipher, "COMPLEX", "This has very <complex> data", false));
return variables;
}
use of com.thoughtworks.go.config.EnvironmentVariablesConfig in project gocd by gocd.
the class EnvironmentVariablesConfigMother method env.
public static EnvironmentVariablesConfig env(String name, String value) {
EnvironmentVariablesConfig config = new EnvironmentVariablesConfig();
config.add(name, value);
return config;
}
Aggregations