Search in sources :

Example 6 with EnvironmentVariablesConfig

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;
}
Also used : MaterialForScheduling(com.thoughtworks.go.server.domain.MaterialForScheduling) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) ArrayList(java.util.ArrayList) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) JsonReader(com.thoughtworks.go.api.representers.JsonReader)

Example 7 with EnvironmentVariablesConfig

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")));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) StageConfig(com.thoughtworks.go.config.StageConfig) Test(org.junit.Test)

Example 8 with EnvironmentVariablesConfig

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")));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) Test(org.junit.Test)

Example 9 with EnvironmentVariablesConfig

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;
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) GoCipher(com.thoughtworks.go.security.GoCipher) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig)

Example 10 with EnvironmentVariablesConfig

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;
}
Also used : EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig)

Aggregations

EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)13 Test (org.junit.Test)8 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)7 AgentConfig (com.thoughtworks.go.config.AgentConfig)3 Agents (com.thoughtworks.go.config.Agents)3 StageConfig (com.thoughtworks.go.config.StageConfig)3 GoCipher (com.thoughtworks.go.security.GoCipher)3 JsonReader (com.thoughtworks.go.api.representers.JsonReader)1 TriggerOptions (com.thoughtworks.go.apiv1.pipelineoperations.representers.TriggerOptions)1 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)1 MaterialForScheduling (com.thoughtworks.go.server.domain.MaterialForScheduling)1 PipelineScheduleOptions (com.thoughtworks.go.server.domain.PipelineScheduleOptions)1 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)1 ArrayList (java.util.ArrayList)1 DOMDocument (org.dom4j.dom.DOMDocument)1