use of com.thoughtworks.go.config.EnvironmentVariableConfig in project gocd by gocd.
the class JobXmlViewModel method toXml.
public Document toXml(XmlWriterContext writerContext) throws DocumentException, IOException {
DOMElement root = new DOMElement("job");
root.addAttribute("name", jobInstance.getName());
Document document = new DOMDocument(root);
root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrl(writerContext.getBaseUrl()));
JobIdentifier identifier = jobInstance.getIdentifier();
root.addElement("id").addCDATA(identifier.asURN());
String pipelineName = identifier.getPipelineName();
StageIdentifier stageId = identifier.getStageIdentifier();
root.addElement("pipeline").addAttribute("name", pipelineName).addAttribute("counter", String.valueOf(stageId.getPipelineCounter())).addAttribute("label", stageId.getPipelineLabel());
root.addElement("stage").addAttribute("name", stageId.getStageName()).addAttribute("counter", stageId.getStageCounter()).addAttribute("href", StageXmlViewModel.httpUrlFor(writerContext.getBaseUrl(), jobInstance.getStageId()));
root.addElement("result").addText(jobInstance.getResult().toString());
root.addElement("state").addText(jobInstance.getState().toString());
Element properties = root.addElement("properties");
for (Property property : writerContext.propertiesForJob(jobInstance.getId())) {
properties.addElement("property").addAttribute("name", property.getKey()).addCDATA(property.getValue());
}
root.addElement("agent").addAttribute("uuid", jobInstance.getAgentUuid());
Element artifacts = root.addElement("artifacts");
artifacts.addAttribute("baseUri", writerContext.artifactBaseUrl(identifier)).addAttribute("pathFromArtifactRoot", writerContext.artifactRootPath(identifier));
JobPlan jobPlan = writerContext.planFor(identifier);
for (ArtifactPlan artifactPlan : jobPlan.getArtifactPlans()) {
artifacts.addElement("artifact").addAttribute("src", artifactPlan.getSrc()).addAttribute("dest", artifactPlan.getDest()).addAttribute("type", artifactPlan.getArtifactType().toString());
}
Element resources = root.addElement("resources");
for (Resource resource : jobPlan.getResources()) {
resources.addElement("resource").addText(resource.getName());
}
Element envVars = root.addElement("environmentvariables");
for (EnvironmentVariableConfig environmentVariableConfig : jobPlan.getVariables()) {
envVars.addElement("variable").addAttribute("name", environmentVariableConfig.getName()).addCDATA(environmentVariableConfig.getDisplayValue());
}
return document;
}
use of com.thoughtworks.go.config.EnvironmentVariableConfig in project gocd by gocd.
the class PipelineScheduleServiceTest method shouldPassEnvironmentLevelEnvironmentVariablesToJobsForNewlyScheduledStage.
@Test
public void shouldPassEnvironmentLevelEnvironmentVariablesToJobsForNewlyScheduledStage() throws Exception {
scheduleAndCompleteInitialPipelines();
Pipeline pipeline = pipelineDao.mostRecentPipeline("go");
Stage stage = scheduleService.scheduleStage(pipeline, "ft", "anonymous", new ScheduleService.NewStageInstanceCreator(goConfigService), new ScheduleService.ExceptioningErrorHandler());
EnvironmentVariablesConfig jobVariables = stage.getJobInstances().first().getPlan().getVariables();
//pipeline, stage, job, env is applied while creating work
assertThat(jobVariables.size(), is(3));
assertThat(jobVariables, hasItem(new EnvironmentVariableConfig("PIPELINE_LVL", "pipeline value")));
assertThat(jobVariables, hasItem(new EnvironmentVariableConfig("STAGE_LVL", "stage value")));
assertThat(jobVariables, hasItem(new EnvironmentVariableConfig("JOB_LVL", "job value")));
}
use of com.thoughtworks.go.config.EnvironmentVariableConfig in project gocd by gocd.
the class EnvironmentVariablesConfigMother method environmentVariables.
public static EnvironmentVariablesConfig environmentVariables() {
EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
GoCipher goCipher = new GoCipher();
variables.add(new EnvironmentVariableConfig(goCipher, "MULTIPLE_LINES", "multiplelines", true));
variables.add(new EnvironmentVariableConfig(goCipher, "COMPLEX", "This has very <complex> data", false));
return variables;
}
Aggregations