use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class BuildComposer method setupEnvironmentVariables.
private BuildCommand setupEnvironmentVariables() {
EnvironmentVariableContext context = environmentVariableContext();
ArrayList<BuildCommand> commands = new ArrayList<>();
commands.add(export("GO_SERVER_URL"));
for (String property : context.getPropertyKeys()) {
commands.add(export(property, context.getProperty(property), context.isPropertySecure(property)));
}
return BuildCommand.compose(commands);
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class JobInstanceSqlMapDaoTest method shouldLoadEnvironmentVariablesForScheduledJobs.
@Test
public void shouldLoadEnvironmentVariablesForScheduledJobs() {
JobInstance newInstance = new JobInstance(JOB_NAME);
newInstance.schedule();
JobInstance instance = jobInstanceDao.save(stageId, newInstance);
instance.setIdentifier(new JobIdentifier(savedPipeline, savedStage, instance));
EnvironmentVariables variables = new EnvironmentVariables();
variables.add("VARIABLE_NAME", "variable value");
variables.add("TRIGGER_VAR", "junk val");
JobPlan plan = new DefaultJobPlan(new Resources(), new ArrayList<>(), new ArrayList<>(), instance.getId(), instance.getIdentifier(), null, variables, new EnvironmentVariables(), null);
jobInstanceDao.save(instance.getId(), plan);
environmentVariableDao.save(savedPipeline.getId(), EnvironmentVariableType.Trigger, environmentVariables("TRIGGER_VAR", "trigger val"));
List<JobPlan> retrieved = jobInstanceDao.orderedScheduledBuilds();
JobPlan reloadedPlan = planForJob(retrieved, plan.getJobId());
EnvironmentVariableContext context = new EnvironmentVariableContext();
reloadedPlan.applyTo(context);
assertThat(reloadedPlan.getVariables(), is(plan.getVariables()));
assertThat(context.getProperty("VARIABLE_NAME"), is("variable value"));
assertThat(context.getProperty("TRIGGER_VAR"), is("trigger val"));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class PackageMaterialTest method shouldPopulateEnvironmentContext.
@Test
public void shouldPopulateEnvironmentContext() {
PackageMaterial material = new PackageMaterial();
PackageRepository repository = PackageRepositoryMother.create("repo-id", "tw-dev", "pluginid", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1"), ConfigurationPropertyMother.create("repo-secure", true, "value")));
material.setPackageDefinition(PackageDefinitionMother.create("p-id", "go-agent", new Configuration(ConfigurationPropertyMother.create("k2", false, "v2"), ConfigurationPropertyMother.create("pkg-secure", true, "value")), repository));
material.setName(new CaseInsensitiveString("tw-dev:go-agent"));
Modifications modifications = new Modifications(new Modification(null, null, null, new Date(), "revision-123"));
EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null);
assertThat(environmentVariableContext.getProperty("GO_REPO_TW_DEV_GO_AGENT_K1"), is("v1"));
assertThat(environmentVariableContext.getProperty("GO_REPO_TW_DEV_GO_AGENT_REPO_SECURE"), is("value"));
assertThat(environmentVariableContext.getPropertyForDisplay("GO_REPO_TW_DEV_GO_AGENT_REPO_SECURE"), is(EnvironmentVariableContext.EnvironmentVariable.MASK_VALUE));
assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_K2"), is("v2"));
assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_PKG_SECURE"), is("value"));
assertThat(environmentVariableContext.getPropertyForDisplay("GO_PACKAGE_TW_DEV_GO_AGENT_PKG_SECURE"), is(EnvironmentVariableContext.EnvironmentVariable.MASK_VALUE));
assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_LABEL"), is("revision-123"));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class EnvironmentVariableTest method addTo_shouldAddEnvironmentVariableToEnvironmentVariableContext.
@Test
public void addTo_shouldAddEnvironmentVariableToEnvironmentVariableContext() {
final EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
final EnvironmentVariable environmentVariable = new EnvironmentVariable("foo", "bar");
environmentVariable.addTo(environmentVariableContext);
verify(environmentVariableContext, times(1)).setProperty("foo", "bar", false);
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class EnvironmentVariableTest method addToIfExists_shouldAddEnvironmentVariableToEnvironmentVariableContextWhenVariableIsAlreadyExistInContext.
@Test
public void addToIfExists_shouldAddEnvironmentVariableToEnvironmentVariableContextWhenVariableIsAlreadyExistInContext() {
final EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
final EnvironmentVariable environmentVariable = new EnvironmentVariable("foo", "bar");
when(environmentVariableContext.hasProperty("foo")).thenReturn(true);
environmentVariable.addToIfExists(environmentVariableContext);
verify(environmentVariableContext, times(1)).setProperty("foo", "bar", false);
}
Aggregations