use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class DefaultWorkCreator method getWork.
public Work getWork(AgentIdentifier agentIdentifier) {
try {
CruiseConfig config = GoConfigMother.pipelineHavingJob(PIPELINE_NAME, STAGE_NAME, JOB_PLAN_NAME, ARTIFACT_FILE.getAbsolutePath(), ARTIFACT_FOLDER.getAbsolutePath());
BuildCause buildCause = BuildCause.createWithEmptyModifications();
BuildAssignment buildAssignment = BuildAssignment.create(toPlan(config), buildCause, new ArrayList<>(), new File("testdata/" + CruiseConfig.WORKING_BASE_DIR + STAGE_NAME), new EnvironmentVariableContext(), new ArtifactStores());
return new BuildWork(buildAssignment, "utf-8");
} catch (Exception e) {
throw bomb(e);
}
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class DefaultJobPlanTest method shouldApplyEnvironmentVariablesWhenRunningTheJob.
@Test
public void shouldApplyEnvironmentVariablesWhenRunningTheJob() {
EnvironmentVariables variables = new EnvironmentVariables();
variables.add("VARIABLE_NAME", "variable value");
DefaultJobPlan plan = new DefaultJobPlan(new Resources(), new ArrayList<>(), new ArrayList<>(), -1, null, null, variables, new EnvironmentVariables(), null);
EnvironmentVariableContext variableContext = new EnvironmentVariableContext();
plan.applyTo(variableContext);
assertThat(variableContext.getProperty("VARIABLE_NAME"), is("variable value"));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class DefaultJobPlanTest method shouldRespectTriggerVariablesOverConfigVariables.
@Test
public void shouldRespectTriggerVariablesOverConfigVariables() {
final EnvironmentVariables environmentVariables = new EnvironmentVariables(Arrays.asList(new EnvironmentVariable("blah", "value"), new EnvironmentVariable("foo", "bar")));
final EnvironmentVariables triggerEnvironmentVariables = new EnvironmentVariables(Arrays.asList(new EnvironmentVariable("blah", "override"), new EnvironmentVariable("another", "anotherValue")));
DefaultJobPlan original = new DefaultJobPlan(new Resources(), new ArrayList<>(), new ArrayList<>(), 0, new JobIdentifier(), "uuid", environmentVariables, triggerEnvironmentVariables, null);
EnvironmentVariableContext variableContext = new EnvironmentVariableContext();
original.applyTo(variableContext);
assertThat(variableContext.getProperty("blah"), is("override"));
assertThat(variableContext.getProperty("foo"), is("bar"));
// becuase its a security issue to let operator set values for unconfigured variables
assertThat(variableContext.getProperty("another"), is(nullValue()));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class ScmMaterialTest method shouldIncludeDestFolderInEnvVariableNameIfMaterialNameNotAvailable.
@Test
public void shouldIncludeDestFolderInEnvVariableNameIfMaterialNameNotAvailable() {
EnvironmentVariableContext context = new EnvironmentVariableContext();
material.setVariableWithName(context, "value", "GO_PROPERTY");
assertThat(context.getProperty("GO_PROPERTY"), is("value"));
context = new EnvironmentVariableContext();
material.setFolder("foo_dir");
material.setVariableWithName(context, "value", "GO_PROPERTY");
assertThat(context.getProperty("GO_PROPERTY_FOO_DIR"), is("value"));
assertThat(context.getProperty("GO_PROPERTY"), is(nullValue()));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class ScmMaterialTest method shouldIncludeMaterialNameInEnvVariableNameIfAvailable.
@Test
public void shouldIncludeMaterialNameInEnvVariableNameIfAvailable() {
EnvironmentVariableContext context = new EnvironmentVariableContext();
material.setVariableWithName(context, "value", "GO_PROPERTY");
assertThat(context.getProperty("GO_PROPERTY"), is("value"));
context = new EnvironmentVariableContext();
material.setName(new CaseInsensitiveString("dummy"));
material.setVariableWithName(context, "value", "GO_PROPERTY");
assertThat(context.getProperty("GO_PROPERTY_DUMMY"), is("value"));
assertThat(context.getProperty("GO_PROPERTY"), is(nullValue()));
}
Aggregations