use of com.thoughtworks.go.config.EnvironmentVariableConfig in project gocd by gocd.
the class JobPlanXmlViewModel method getXmlForJobPlan.
private DOMElement getXmlForJobPlan(XmlWriterContext writerContext, WaitingJobPlan waitingJobPlan) {
JobPlan jobPlan = waitingJobPlan.jobPlan();
DOMElement root = new DOMElement("job");
root.addAttribute("name", jobPlan.getName()).addAttribute("id", String.valueOf(jobPlan.getJobId()));
root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrlFor(writerContext.getBaseUrl(), jobPlan.getIdentifier()));
root.addElement("buildLocator").addText(jobPlan.getIdentifier().buildLocator());
if (!StringUtil.isBlank(waitingJobPlan.envName())) {
root.addElement("environment").addText(waitingJobPlan.envName());
}
if (!jobPlan.getResources().isEmpty()) {
DOMElement resources = new DOMElement("resources");
for (Resource resource : jobPlan.getResources()) {
resources.addElement("resource").addCDATA(resource.getName());
}
root.add(resources);
}
if (!jobPlan.getVariables().isEmpty()) {
DOMElement envVars = new DOMElement("environmentVariables");
for (EnvironmentVariableConfig environmentVariableConfig : jobPlan.getVariables()) {
envVars.addElement("variable").addAttribute("name", environmentVariableConfig.getName()).addText(environmentVariableConfig.getDisplayValue());
}
root.add(envVars);
}
return root;
}
use of com.thoughtworks.go.config.EnvironmentVariableConfig in project gocd by gocd.
the class EnvironmentVariableSqlMapDaoIntegrationTest method shouldSaveSecureEnvironmentVariable.
@Test
public void shouldSaveSecureEnvironmentVariable() throws InvalidCipherTextException {
EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
String plainText = "plainText";
String key = "key";
GoCipher goCipher = new GoCipher();
variables.add(new EnvironmentVariableConfig(goCipher, key, plainText, true));
dao.save(1L, Job, variables);
EnvironmentVariablesConfig actual = dao.load(1L, Job);
assertThat(actual.get(0).getName(), is(key));
assertThat(actual.get(0).getValue(), is(plainText));
assertThat(actual.get(0).isSecure(), is(true));
}
use of com.thoughtworks.go.config.EnvironmentVariableConfig in project gocd by gocd.
the class EnvironmentVariableSqlMapDaoIntegrationTest method shouldSavePlainTextEnvironmentVariable.
@Test
public void shouldSavePlainTextEnvironmentVariable() {
EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
String plainText = "plainText";
String key = "key";
variables.add(new EnvironmentVariableConfig(new GoCipher(), key, plainText, false));
dao.save(1L, Job, variables);
EnvironmentVariablesConfig actual = dao.load(1L, Job);
assertThat(actual.get(0).getName(), is(key));
assertThat(actual.get(0).getValue(), is(plainText));
assertThat(actual.get(0).isSecure(), is(false));
}
use of com.thoughtworks.go.config.EnvironmentVariableConfig in project gocd by gocd.
the class PipelineSqlMapDaoIntegrationTest method shouldPersistBuildCauseEnvironmentVariables.
@Test
public void shouldPersistBuildCauseEnvironmentVariables() throws SQLException {
MaterialRevisions materialRevisions = ModificationsMother.multipleModifications();
BuildCause buildCause = BuildCause.createManualForced(materialRevisions, Username.ANONYMOUS);
EnvironmentVariablesConfig environmentVariablesConfig = new EnvironmentVariablesConfig();
environmentVariablesConfig.add(new EnvironmentVariableConfig("VAR1", "value one"));
environmentVariablesConfig.add(new EnvironmentVariableConfig("VAR2", "value two"));
buildCause.addOverriddenVariables(environmentVariablesConfig);
Pipeline pipeline = new Pipeline("Test", buildCause);
save(pipeline);
Pipeline loaded = pipelineDao.mostRecentPipeline("Test");
EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
variables.add("VAR1", "value one");
variables.add("VAR2", "value two");
assertThat(loaded.getBuildCause().getVariables(), is(variables));
assertThat(loaded.scheduleTimeVariables(), is(variables));
}
use of com.thoughtworks.go.config.EnvironmentVariableConfig in project gocd by gocd.
the class DefaultSchedulingContextTest method shouldSetEnvironmentVariablesOnSchedulingContext.
@Test
public void shouldSetEnvironmentVariablesOnSchedulingContext() throws Exception {
EnvironmentVariablesConfig existing = new EnvironmentVariablesConfig();
existing.add("firstVar", "firstVal");
existing.add("overriddenVar", "originalVal");
SchedulingContext schedulingContext = new DefaultSchedulingContext();
schedulingContext = schedulingContext.overrideEnvironmentVariables(existing);
EnvironmentVariablesConfig stageLevel = new EnvironmentVariablesConfig();
stageLevel.add("stageVar", "stageVal");
stageLevel.add("overriddenVar", "overriddenVal");
StageConfig config = StageConfigMother.custom("test", Approval.automaticApproval());
config.setVariables(stageLevel);
ReflectionUtil.setField(schedulingContext, "rerun", true);
SchedulingContext context = schedulingContext.overrideEnvironmentVariables(config.getVariables());
assertThat(context.isRerun(), is(true));
EnvironmentVariablesConfig environmentVariablesUsed = context.getEnvironmentVariablesConfig();
assertThat(environmentVariablesUsed.size(), is(3));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("firstVar", "firstVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("overriddenVar", "overriddenVal")));
assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("stageVar", "stageVal")));
}
Aggregations