Search in sources :

Example 1 with StageConfig

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

the class DefaultSchedulingContextTest method shouldCreatePermittedAgentContextCorrectly.

@Test
public void shouldCreatePermittedAgentContextCorrectly() throws Exception {
    AgentConfig linux = agent("uuid1", "linux");
    AgentConfig windows = agent("uuid2", "windows");
    windows.disable();
    Agents matchingAgents = new Agents(linux, windows);
    EnvironmentVariablesConfig existing = new EnvironmentVariablesConfig();
    existing.add("firstVar", "firstVal");
    existing.add("overriddenVar", "originalVal");
    SchedulingContext schedulingContext = new DefaultSchedulingContext("approver", matchingAgents);
    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);
    SchedulingContext context = schedulingContext.overrideEnvironmentVariables(config.getVariables());
    ReflectionUtil.setField(context, "rerun", true);
    SchedulingContext permittedAgentContext = context.permittedAgent("uuid1");
    Agents agents = (Agents) ReflectionUtil.getField(permittedAgentContext, "agents");
    assertThat(agents.size(), is(1));
    assertThat(agents.get(0).getAgentIdentifier().getUuid(), is("uuid1"));
    assertThat(permittedAgentContext.isRerun(), is(true));
    assertThat(permittedAgentContext.getApprovedBy(), is("approver"));
    EnvironmentVariablesConfig environmentVariablesUsed = permittedAgentContext.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 : AgentConfig(com.thoughtworks.go.config.AgentConfig) EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) Agents(com.thoughtworks.go.config.Agents) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) StageConfig(com.thoughtworks.go.config.StageConfig) Test(org.junit.Test)

Example 2 with StageConfig

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

the class DefaultSchedulingContextTest method shouldCreateRerunSchedulingContextCorrectly.

@Test
public void shouldCreateRerunSchedulingContextCorrectly() throws Exception {
    AgentConfig linux = agent("uuid1", "linux");
    AgentConfig windows = agent("uuid2", "windows");
    windows.disable();
    Agents matchingAgents = new Agents(linux, windows);
    EnvironmentVariablesConfig existing = new EnvironmentVariablesConfig();
    existing.add("firstVar", "firstVal");
    existing.add("overriddenVar", "originalVal");
    SchedulingContext schedulingContext = new DefaultSchedulingContext("approver", matchingAgents);
    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);
    SchedulingContext context = schedulingContext.overrideEnvironmentVariables(config.getVariables());
    SchedulingContext rerunContext = context.rerunContext();
    assertThat(rerunContext.isRerun(), is(true));
    assertThat(rerunContext.getApprovedBy(), is("approver"));
    Agents agents = (Agents) ReflectionUtil.getField(rerunContext, "agents");
    assertThat(agents, is(matchingAgents));
    EnvironmentVariablesConfig environmentVariablesUsed = rerunContext.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 : AgentConfig(com.thoughtworks.go.config.AgentConfig) EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) Agents(com.thoughtworks.go.config.Agents) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) StageConfig(com.thoughtworks.go.config.StageConfig) Test(org.junit.Test)

Example 3 with StageConfig

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

the class MyGoController method getStagesModelsFor.

private List<PipelineViewModel.StageViewModel> getStagesModelsFor(PipelineConfig pipelineConfig) {
    List<PipelineViewModel.StageViewModel> stageModels = new ArrayList<>();
    stageModels.add(new PipelineViewModel.StageViewModel(GoConstants.ANY_STAGE));
    for (StageConfig stageConfig : pipelineConfig) {
        stageModels.add(new PipelineViewModel.StageViewModel(CaseInsensitiveString.str(stageConfig.name())));
    }
    return stageModels;
}
Also used : PipelineViewModel(com.thoughtworks.go.server.presentation.models.PipelineViewModel) StageConfig(com.thoughtworks.go.config.StageConfig)

Example 4 with StageConfig

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

the class PipelineScheduleServiceTest method setup.

@Before
public void setup() throws Exception {
    configHelper = new GoConfigFileHelper();
    configHelper.usingCruiseConfigDao(goConfigDao);
    configHelper.onSetUp();
    testRepo = new SvnTestRepo("testSvnRepo");
    dbHelper.onSetUp();
    repository = new SvnCommand(null, testRepo.projectRepositoryUrl());
    mingleConfig = configHelper.addPipeline("mingle", STAGE_NAME, repository, "unit", "functional");
    goConfig = configHelper.addPipeline("go", STAGE_NAME, repository, "unit");
    StageConfig ftStageConfig = StageConfigMother.custom("ft", "twist");
    ftStageConfig.jobConfigByConfigName(new CaseInsensitiveString("twist")).addVariable("JOB_LVL", "job value");
    ftStageConfig.setVariables(env("STAGE_LVL", "stage value"));
    configHelper.addStageToPipeline("go", ftStageConfig);
    configHelper.addEnvironmentVariableToPipeline("go", env("PIPELINE_LVL", "pipeline value"));
    configHelper.addEnvironments("uat");
    EnvironmentConfig uatEnv = configHelper.currentConfig().getEnvironments().named(new CaseInsensitiveString("uat"));
    uatEnv.addPipeline(new CaseInsensitiveString("go"));
    uatEnv.addEnvironmentVariable("ENV_LVL", "env value");
    evolveConfig = configHelper.addPipeline("evolve", STAGE_NAME, repository, "unit");
    goCache.clear();
}
Also used : EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) SvnTestRepo(com.thoughtworks.go.helper.SvnTestRepo) SvnCommand(com.thoughtworks.go.domain.materials.svn.SvnCommand) GoConfigFileHelper(com.thoughtworks.go.util.GoConfigFileHelper) StageConfig(com.thoughtworks.go.config.StageConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Before(org.junit.Before)

Example 5 with StageConfig

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

the class StageInfoAdapterTest method shouldReturnCorrectAutoApprovedStatus.

@Test
public void shouldReturnCorrectAutoApprovedStatus() throws Exception {
    StageConfig stage = StageConfigMother.custom("dev", new JobConfigs());
    assertThat(stage.requiresApproval(), is(false));
    assertThat(new StageInfoAdapter(stage).isAutoApproved(), is(true));
}
Also used : JobConfigs(com.thoughtworks.go.config.JobConfigs) StageConfig(com.thoughtworks.go.config.StageConfig) Test(org.junit.Test)

Aggregations

StageConfig (com.thoughtworks.go.config.StageConfig)30 Test (org.junit.Test)12 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)8 TimeProvider (com.thoughtworks.go.util.TimeProvider)4 Agents (com.thoughtworks.go.config.Agents)3 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)3 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 JobConfigs (com.thoughtworks.go.config.JobConfigs)2 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)2 DefaultSchedulingContext (com.thoughtworks.go.domain.DefaultSchedulingContext)2 NullStage (com.thoughtworks.go.domain.NullStage)2 Stage (com.thoughtworks.go.domain.Stage)2 InstanceFactory (com.thoughtworks.go.server.service.InstanceFactory)2 Map (java.util.Map)2 AdminUser (com.thoughtworks.go.config.AdminUser)1 Approval (com.thoughtworks.go.config.Approval)1 AuthConfig (com.thoughtworks.go.config.AuthConfig)1 EnvironmentConfig (com.thoughtworks.go.config.EnvironmentConfig)1