use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class PackageMaterial method populateEnvironmentContext.
@Override
public void populateEnvironmentContext(EnvironmentVariableContext context, MaterialRevision materialRevision, File workingDir) {
context.setProperty(upperCase(format("GO_PACKAGE_%s_LABEL", escapeEnvironmentVariable(getName().toString()))), materialRevision.getRevision().getRevision(), false);
for (ConfigurationProperty configurationProperty : getPackageDefinition().getRepository().getConfiguration()) {
context.setProperty(getEnvironmentVariableKey("GO_REPO_%s_%s", configurationProperty.getConfigurationKey().getName()), configurationProperty.getValue(), configurationProperty.isSecure());
}
for (ConfigurationProperty configurationProperty : getPackageDefinition().getConfiguration()) {
context.setProperty(getEnvironmentVariableKey("GO_PACKAGE_%s_%s", configurationProperty.getConfigurationKey().getName()), configurationProperty.getValue(), configurationProperty.isSecure());
}
HashMap<String, String> additionalData = materialRevision.getLatestModification().getAdditionalDataMap();
if (additionalData != null) {
for (Map.Entry<String, String> entry : additionalData.entrySet()) {
boolean isSecure = false;
for (EnvironmentVariableContext.EnvironmentVariable secureEnvironmentVariable : context.getSecureEnvironmentVariables()) {
String urlEncodedValue = null;
try {
urlEncodedValue = URLEncoder.encode(secureEnvironmentVariable.value(), "UTF-8");
} catch (UnsupportedEncodingException e) {
}
boolean isSecureEnvironmentVariableEncoded = !StringUtils.isBlank(urlEncodedValue) && !secureEnvironmentVariable.value().equals(urlEncodedValue);
if (isSecureEnvironmentVariableEncoded && entry.getValue().contains(urlEncodedValue)) {
isSecure = true;
break;
}
}
String key = entry.getKey();
String value = entry.getValue();
context.setProperty(getEnvironmentVariableKey("GO_PACKAGE_%s_%s", key), value, isSecure);
}
}
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class JobInstanceSqlMapDaoTest method shouldSaveEnvironmentVariables.
@Test
public void shouldSaveEnvironmentVariables() {
JobInstance instance = jobInstanceDao.save(stageId, new JobInstance(JOB_NAME));
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"));
JobPlan retrieved = jobInstanceDao.loadPlan(plan.getJobId());
assertThat(retrieved.getVariables(), is(plan.getVariables()));
EnvironmentVariableContext context = new EnvironmentVariableContext();
retrieved.applyTo(context);
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 AntTaskBuilderTest method shouldFailWhenTargetDoesNotExist.
@Test
public void shouldFailWhenTargetDoesNotExist() {
String target = "not-exist-target";
String buildXml = "./build.xml";
antTask.setBuildFile(buildXml);
antTask.setTarget(target);
Builder builder = antTaskBuilder.createBuilder(builderFactory, antTask, TasksTest.pipelineStub(PIPELINE_LABEL, "."), resolver);
try {
builder.build(new StubGoPublisher(), new EnvironmentVariableContext(), taskEntension, null, null, "utf-8");
} catch (CruiseControlException e) {
assertThat(e.getMessage(), containsString("Build failed. Command ant reported [BUILD FAILED]."));
}
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class KillAllChildProcessTaskBuilderTest method shouldKillAllChildProcessOnbuild.
// 11 minutes
@Test(timeout = 11 * 60 * 1000)
public void shouldKillAllChildProcessOnbuild() throws Exception {
ProcessWrapper processWrapper = CommandLine.createCommandLine("sleep").withArg(String.valueOf(10 * 60)).withEncoding("utf-8").execute(ProcessOutputStreamConsumer.inMemoryConsumer(), new EnvironmentVariableContext(), // 60 mins
null);
assertThat(processWrapper.isRunning(), is(true));
DefaultGoPublisher publisher = mock(DefaultGoPublisher.class);
EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
long before = getSystemTime();
Builder builder = new KillAllChildProcessTaskBuilder().createBuilder(builderFactory, new KillAllChildProcessTask(), null, null);
builder.build(publisher, environmentVariableContext, null, null, null, "utf-8");
assertThat(processWrapper.waitForExit(), is(greaterThan(0)));
// min = 10; sec = 60*min; mills = 1000*sec; micro = 1000*mills; nano = 1000*micro;
assertThat(getSystemTime() - before, is(lessThan(10 * 60 * 1000 * 1000 * 1000L)));
}
Aggregations