Search in sources :

Example 11 with EnvironmentVariablesConfig

use of com.thoughtworks.go.config.EnvironmentVariablesConfig in project gocd by gocd.

the class ScheduleStageTest method shouldResolveEnvironmentVariablesForJobReRun.

@Test
public void shouldResolveEnvironmentVariablesForJobReRun() {
    Pipeline pipeline = fixture.createdPipelineWithAllStagesPassed();
    Stage oldStage = stageDao.stageByIdWithBuilds(pipeline.getStages().byName(fixture.devStage).getId());
    EnvironmentVariablesConfig pipelineVariables = new EnvironmentVariablesConfig();
    pipelineVariables.add("pipelineEnv", "pipelineFoo");
    pipelineVariables.add("stageEnv", "pipelineBar");
    pipelineVariables.add("jobEnv", "pipelineBaz");
    configHelper.addEnvironmentVariableToPipeline(fixture.pipelineName, pipelineVariables);
    EnvironmentVariablesConfig stageVariables = new EnvironmentVariablesConfig();
    stageVariables.add("stageEnv", "stageBar");
    stageVariables.add("jobEnv", "stageBaz");
    configHelper.addEnvironmentVariableToStage(fixture.pipelineName, fixture.devStage, stageVariables);
    EnvironmentVariablesConfig jobVariables = new EnvironmentVariablesConfig();
    jobVariables.add("jobEnv", "jobBaz");
    configHelper.addEnvironmentVariableToJob(fixture.pipelineName, fixture.devStage, fixture.JOB_FOR_DEV_STAGE, jobVariables);
    Stage stage = scheduleService.rerunJobs(oldStage, a(fixture.JOB_FOR_DEV_STAGE), new HttpOperationResult());
    EnvironmentVariables expectedVariableOrder = new EnvironmentVariables();
    expectedVariableOrder.add("pipelineEnv", "pipelineFoo");
    expectedVariableOrder.add("stageEnv", "stageBar");
    expectedVariableOrder.add("jobEnv", "jobBaz");
    JobInstances jobInstances = stage.getJobInstances();
    assertThat(jobInstances.getByName(fixture.JOB_FOR_DEV_STAGE).getPlan().getVariables(), is(expectedVariableOrder));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) Test(org.junit.Test)

Example 12 with EnvironmentVariablesConfig

use of com.thoughtworks.go.config.EnvironmentVariablesConfig in project gocd by gocd.

the class ScheduleStageTest method shouldResolveEnvironmentVariablesForStateReRun.

@Test
public void shouldResolveEnvironmentVariablesForStateReRun() throws Exception {
    Pipeline pipeline = fixture.createdPipelineWithAllStagesPassed();
    EnvironmentVariablesConfig pipelineVariables = new EnvironmentVariablesConfig();
    pipelineVariables.add("pipelineEnv", "pipelineFoo");
    pipelineVariables.add("stageEnv", "pipelineBar");
    pipelineVariables.add("jobEnv", "pipelineBaz");
    configHelper.addEnvironmentVariableToPipeline(fixture.pipelineName, pipelineVariables);
    EnvironmentVariablesConfig stageVariables = new EnvironmentVariablesConfig();
    stageVariables.add("stageEnv", "stageBar");
    stageVariables.add("jobEnv", "stageBaz");
    configHelper.addEnvironmentVariableToStage(fixture.pipelineName, fixture.devStage, stageVariables);
    EnvironmentVariablesConfig jobVariables = new EnvironmentVariablesConfig();
    jobVariables.add("jobEnv", "jobBaz");
    configHelper.addEnvironmentVariableToJob(fixture.pipelineName, fixture.devStage, fixture.JOB_FOR_DEV_STAGE, jobVariables);
    Stage stage = scheduleService.rerunStage(pipeline.getName(), String.valueOf(pipeline.getCounter()), fixture.devStage);
    dbHelper.passStage(stage);
    EnvironmentVariables expectedVariableOrder = new EnvironmentVariables();
    expectedVariableOrder.add("pipelineEnv", "pipelineFoo");
    expectedVariableOrder.add("stageEnv", "stageBar");
    expectedVariableOrder.add("jobEnv", "jobBaz");
    JobInstances jobInstances = stage.getJobInstances();
    assertThat(jobInstances.getByName(fixture.JOB_FOR_DEV_STAGE).getPlan().getVariables(), is(expectedVariableOrder));
}
Also used : EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) Test(org.junit.Test)

Example 13 with EnvironmentVariablesConfig

use of com.thoughtworks.go.config.EnvironmentVariablesConfig in project gocd by gocd.

the class PipelineOperationsControllerV1Delegate method triggerOptions.

public String triggerOptions(Request request, Response response) throws IOException {
    String pipelineName = request.params("pipeline_name");
    EnvironmentVariablesConfig variables = goConfigService.variablesFor(pipelineName);
    PipelineInstanceModel pipelineInstanceModel = pipelineHistoryService.latest(pipelineName, currentUsername());
    TriggerOptions triggerOptions = new TriggerOptions(variables, pipelineInstanceModel);
    return writerForTopLevelObject(request, response, writer -> TriggerWithOptionsViewRepresenter.toJSON(writer, triggerOptions));
}
Also used : PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) TriggerOptions(com.thoughtworks.go.apiv1.pipelineoperations.representers.TriggerOptions) 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