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));
}
}
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"));
}
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"));
}
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"));
}
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));
}
Aggregations