Search in sources :

Example 21 with StageConfig

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")));
}
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 22 with StageConfig

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

Example 23 with StageConfig

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());
    }
}
Also used : NullStage(com.thoughtworks.go.domain.NullStage) Stages(com.thoughtworks.go.domain.Stages) StageConfig(com.thoughtworks.go.config.StageConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 24 with StageConfig

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);
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) Materials(com.thoughtworks.go.config.materials.Materials) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageConfig(com.thoughtworks.go.config.StageConfig) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) JobConfigs(com.thoughtworks.go.config.JobConfigs) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision)

Example 25 with StageConfig

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