Search in sources :

Example 11 with EnvironmentVariableConfig

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;
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) ArtifactPlan(com.thoughtworks.go.config.ArtifactPlan) JobPlan(com.thoughtworks.go.domain.JobPlan) Element(org.dom4j.Element) DOMElement(org.dom4j.dom.DOMElement) DOMDocument(org.dom4j.dom.DOMDocument) Resource(com.thoughtworks.go.config.Resource) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DOMElement(org.dom4j.dom.DOMElement) Document(org.dom4j.Document) DOMDocument(org.dom4j.dom.DOMDocument) Property(com.thoughtworks.go.domain.Property)

Example 12 with EnvironmentVariableConfig

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")));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) Test(org.junit.Test)

Example 13 with EnvironmentVariableConfig

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;
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) GoCipher(com.thoughtworks.go.security.GoCipher) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig)

Aggregations

EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)13 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)11 Test (org.junit.Test)9 GoCipher (com.thoughtworks.go.security.GoCipher)5 StageConfig (com.thoughtworks.go.config.StageConfig)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 Agents (com.thoughtworks.go.config.Agents)2 Resource (com.thoughtworks.go.config.Resource)2 JobPlan (com.thoughtworks.go.domain.JobPlan)2 WaitingJobPlan (com.thoughtworks.go.domain.WaitingJobPlan)2 Document (org.dom4j.Document)2 DOMDocument (org.dom4j.dom.DOMDocument)2 DOMElement (org.dom4j.dom.DOMElement)2 ArtifactPlan (com.thoughtworks.go.config.ArtifactPlan)1 DefaultJobPlan (com.thoughtworks.go.domain.DefaultJobPlan)1 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 Property (com.thoughtworks.go.domain.Property)1 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)1 XmlWriterContext (com.thoughtworks.go.domain.XmlWriterContext)1 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)1