Search in sources :

Example 36 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class DefaultWorkCreator method getWork.

public Work getWork(AgentIdentifier agentIdentifier) {
    try {
        CruiseConfig config = GoConfigMother.pipelineHavingJob(PIPELINE_NAME, STAGE_NAME, JOB_PLAN_NAME, ARTIFACT_FILE.getAbsolutePath(), ARTIFACT_FOLDER.getAbsolutePath());
        BuildCause buildCause = BuildCause.createWithEmptyModifications();
        BuildAssignment buildAssignment = BuildAssignment.create(toPlan(config), buildCause, new ArrayList<>(), new File("testdata/" + CruiseConfig.WORKING_BASE_DIR + STAGE_NAME), new EnvironmentVariableContext(), new ArtifactStores());
        return new BuildWork(buildAssignment, "utf-8");
    } catch (Exception e) {
        throw bomb(e);
    }
}
Also used : ArtifactStores(com.thoughtworks.go.config.ArtifactStores) BuildAssignment(com.thoughtworks.go.remote.work.BuildAssignment) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) File(java.io.File) BuildWork(com.thoughtworks.go.remote.work.BuildWork) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) IOException(java.io.IOException) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 37 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class DefaultJobPlanTest method shouldApplyEnvironmentVariablesWhenRunningTheJob.

@Test
public void shouldApplyEnvironmentVariablesWhenRunningTheJob() {
    EnvironmentVariables variables = new EnvironmentVariables();
    variables.add("VARIABLE_NAME", "variable value");
    DefaultJobPlan plan = new DefaultJobPlan(new Resources(), new ArrayList<>(), new ArrayList<>(), -1, null, null, variables, new EnvironmentVariables(), null);
    EnvironmentVariableContext variableContext = new EnvironmentVariableContext();
    plan.applyTo(variableContext);
    assertThat(variableContext.getProperty("VARIABLE_NAME"), is("variable value"));
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 38 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class DefaultJobPlanTest method shouldRespectTriggerVariablesOverConfigVariables.

@Test
public void shouldRespectTriggerVariablesOverConfigVariables() {
    final EnvironmentVariables environmentVariables = new EnvironmentVariables(Arrays.asList(new EnvironmentVariable("blah", "value"), new EnvironmentVariable("foo", "bar")));
    final EnvironmentVariables triggerEnvironmentVariables = new EnvironmentVariables(Arrays.asList(new EnvironmentVariable("blah", "override"), new EnvironmentVariable("another", "anotherValue")));
    DefaultJobPlan original = new DefaultJobPlan(new Resources(), new ArrayList<>(), new ArrayList<>(), 0, new JobIdentifier(), "uuid", environmentVariables, triggerEnvironmentVariables, null);
    EnvironmentVariableContext variableContext = new EnvironmentVariableContext();
    original.applyTo(variableContext);
    assertThat(variableContext.getProperty("blah"), is("override"));
    assertThat(variableContext.getProperty("foo"), is("bar"));
    // becuase its a security issue to let operator set values for unconfigured variables
    assertThat(variableContext.getProperty("another"), is(nullValue()));
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 39 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class ScmMaterialTest method shouldIncludeDestFolderInEnvVariableNameIfMaterialNameNotAvailable.

@Test
public void shouldIncludeDestFolderInEnvVariableNameIfMaterialNameNotAvailable() {
    EnvironmentVariableContext context = new EnvironmentVariableContext();
    material.setVariableWithName(context, "value", "GO_PROPERTY");
    assertThat(context.getProperty("GO_PROPERTY"), is("value"));
    context = new EnvironmentVariableContext();
    material.setFolder("foo_dir");
    material.setVariableWithName(context, "value", "GO_PROPERTY");
    assertThat(context.getProperty("GO_PROPERTY_FOO_DIR"), is("value"));
    assertThat(context.getProperty("GO_PROPERTY"), is(nullValue()));
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 40 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class ScmMaterialTest method shouldIncludeMaterialNameInEnvVariableNameIfAvailable.

@Test
public void shouldIncludeMaterialNameInEnvVariableNameIfAvailable() {
    EnvironmentVariableContext context = new EnvironmentVariableContext();
    material.setVariableWithName(context, "value", "GO_PROPERTY");
    assertThat(context.getProperty("GO_PROPERTY"), is("value"));
    context = new EnvironmentVariableContext();
    material.setName(new CaseInsensitiveString("dummy"));
    material.setVariableWithName(context, "value", "GO_PROPERTY");
    assertThat(context.getProperty("GO_PROPERTY_DUMMY"), is("value"));
    assertThat(context.getProperty("GO_PROPERTY"), is(nullValue()));
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)94 Test (org.junit.Test)74 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)19 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)16 File (java.io.File)14 Date (java.util.Date)13 Modification (com.thoughtworks.go.domain.materials.Modification)12 Modifications (com.thoughtworks.go.domain.materials.Modifications)10 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)9 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)9 Before (org.junit.Before)8 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)7 ArtifactStores (com.thoughtworks.go.config.ArtifactStores)6 Materials (com.thoughtworks.go.config.materials.Materials)6 Builder (com.thoughtworks.go.domain.builder.Builder)6 HashMap (java.util.HashMap)6 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)5 RunIfConfigs (com.thoughtworks.go.domain.RunIfConfigs)5 PackageMaterialRevision (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision)5 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)5