Search in sources :

Example 6 with EnvironmentVariableConfig

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;
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) JobPlan(com.thoughtworks.go.domain.JobPlan) WaitingJobPlan(com.thoughtworks.go.domain.WaitingJobPlan) Resource(com.thoughtworks.go.config.Resource) DOMElement(org.dom4j.dom.DOMElement)

Example 7 with EnvironmentVariableConfig

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

Example 8 with EnvironmentVariableConfig

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

Example 9 with EnvironmentVariableConfig

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

Example 10 with EnvironmentVariableConfig

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

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