Search in sources :

Example 51 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class BuildWorkTest method shouldSendAResultStatusToServerWhenAThrowableErrorIsThrown.

@Test
public void shouldSendAResultStatusToServerWhenAThrowableErrorIsThrown() throws Exception {
    BuildAssignment buildAssignment = mock(BuildAssignment.class);
    when(buildAssignment.shouldFetchMaterials()).thenThrow(new AssertionError());
    when(buildAssignment.initialEnvironmentVariableContext()).thenReturn(new EnvironmentVariableContext());
    when(buildAssignment.getWorkingDirectory()).thenReturn(new File("current"));
    when(buildAssignment.getJobIdentifier()).thenReturn(JOB_IDENTIFIER);
    buildWork = new BuildWork(buildAssignment, "utf-8");
    try {
        buildWork.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, buildRepository, artifactManipulator, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension, null, pluginRequestProcessorRegistry));
        fail("Should have thrown an assertion error");
    } catch (AssertionError e) {
        assertThat(buildRepository.results.isEmpty(), is(true));
        assertThat(buildRepository.states.size(), is(1));
        assertThat(buildRepository.states.get(0), is(JobState.Preparing));
    }
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) File(java.io.File) Test(org.junit.Test)

Example 52 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class EnvironmentConfigServiceTest method shouldListEnvironmentVariablesDefinedForAnEnvironment.

@Test
public void shouldListEnvironmentVariablesDefinedForAnEnvironment() throws Exception {
    EnvironmentsConfig environmentConfigs = new EnvironmentsConfig();
    BasicEnvironmentConfig environment = environment("uat");
    environment.addEnvironmentVariable("Var1", "Value1");
    environment.addEnvironmentVariable("Var2", "Value2");
    environmentConfigs.add(environment);
    environmentConfigService.sync(environmentConfigs);
    EnvironmentVariableContext environmentVariableContext = environmentConfigService.environmentVariableContextFor("uat-pipeline");
    assertThat(environmentVariableContext.getProperties().size(), is(3));
    assertThat(environmentVariableContext.getProperty("GO_ENVIRONMENT_NAME"), is("uat"));
    assertThat(environmentVariableContext.getProperty("Var1"), is("Value1"));
    assertThat(environmentVariableContext.getProperty("Var2"), is("Value2"));
    assertNull(environmentConfigService.environmentVariableContextFor("non-existent-pipeline"));
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 53 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class BuildAssignmentTest method shouldInitializeEnvironmentContextFromJobPlanWithTriggerVariablesOverridingEnvVariablesFromJob.

@Test
public void shouldInitializeEnvironmentContextFromJobPlanWithTriggerVariablesOverridingEnvVariablesFromJob() throws Exception {
    DefaultJobPlan defaultJobPlan = jobForPipeline("foo");
    EnvironmentVariables triggerVariables = new EnvironmentVariables();
    triggerVariables.add("key1", "override");
    triggerVariables.add("key3", "value3");
    EnvironmentVariables variables = new EnvironmentVariables();
    variables.add("key1", "value1");
    variables.add("key2", "value2");
    defaultJobPlan.setTriggerVariables(triggerVariables);
    defaultJobPlan.setVariables(variables);
    BuildAssignment buildAssignment = BuildAssignment.create(defaultJobPlan, BuildCause.createManualForced(), new ArrayList<>(), null, null, new ArtifactStores());
    EnvironmentVariableContext context = buildAssignment.initialEnvironmentVariableContext();
    assertThat(context.getProperties().size(), is(9));
    assertThat(context.getProperty("key1"), is("override"));
    assertThat(context.getProperty("key2"), is("value2"));
}
Also used : ArtifactStores(com.thoughtworks.go.config.ArtifactStores) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 54 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class BuildAssignmentTest method shouldIntializeEnvironmentContextWithJobPlanEnvironmentVariablesOveridingEnvVariablesFromTheEnvironment.

@Test
public void shouldIntializeEnvironmentContextWithJobPlanEnvironmentVariablesOveridingEnvVariablesFromTheEnvironment() throws Exception {
    DefaultJobPlan defaultJobPlan = jobForPipeline("foo");
    EnvironmentVariables variables = new EnvironmentVariables();
    variables.add("key1", "value_from_job_plan");
    variables.add("key2", "value2");
    defaultJobPlan.setVariables(variables);
    EnvironmentVariableContext contextFromEnvironment = new EnvironmentVariableContext("key1", "value_from_environment");
    contextFromEnvironment.setProperty("key3", "value3", false);
    BuildAssignment buildAssignment = BuildAssignment.create(defaultJobPlan, BuildCause.createManualForced(), new ArrayList<>(), null, contextFromEnvironment, new ArtifactStores());
    EnvironmentVariableContext context = buildAssignment.initialEnvironmentVariableContext();
    assertThat(context.getProperties().size(), is(10));
    assertThat(context.getProperty("key1"), is("value_from_job_plan"));
    assertThat(context.getProperty("key2"), is("value2"));
    assertThat(context.getProperty("key3"), is("value3"));
}
Also used : ArtifactStores(com.thoughtworks.go.config.ArtifactStores) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 55 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class BuildAssignmentTest method shouldSetUpGoGeneratedEnvironmentContextCorrectly.

@Test
public void shouldSetUpGoGeneratedEnvironmentContextCorrectly() throws Exception {
    new SystemEnvironment().setProperty("serviceUrl", "some_random_place");
    BuildAssignment buildAssigment = createAssignment(null);
    EnvironmentVariableContext environmentVariableContext = buildAssigment.initialEnvironmentVariableContext();
    assertThat(environmentVariableContext.getProperty("GO_REVISION"), Matchers.is("3"));
    assertThat(environmentVariableContext.getProperty("GO_PIPELINE_NAME"), Matchers.is(PIPELINE_NAME));
    assertThat(environmentVariableContext.getProperty("GO_PIPELINE_LABEL"), Matchers.is("1"));
    assertThat(environmentVariableContext.getProperty("GO_STAGE_NAME"), Matchers.is(STAGE_NAME));
    assertThat(environmentVariableContext.getProperty("GO_STAGE_COUNTER"), Matchers.is("1"));
    assertThat(environmentVariableContext.getProperty("GO_JOB_NAME"), Matchers.is(JOB_NAME));
    assertThat(environmentVariableContext.getProperty("GO_TRIGGER_USER"), Matchers.is(TRIGGERED_BY_USER));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Aggregations

EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)94 Test (org.junit.Test)74 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)19 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)16 File (java.io.File)14 Date (java.util.Date)13 Modification (com.thoughtworks.go.domain.materials.Modification)12 Modifications (com.thoughtworks.go.domain.materials.Modifications)10 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)9 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)9 Before (org.junit.Before)8 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)7 ArtifactStores (com.thoughtworks.go.config.ArtifactStores)6 Materials (com.thoughtworks.go.config.materials.Materials)6 Builder (com.thoughtworks.go.domain.builder.Builder)6 HashMap (java.util.HashMap)6 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)5 RunIfConfigs (com.thoughtworks.go.domain.RunIfConfigs)5 PackageMaterialRevision (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision)5 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)5