Search in sources :

Example 6 with EnvironmentVariableContext

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

the class BuildComposer method setupEnvironmentVariables.

private BuildCommand setupEnvironmentVariables() {
    EnvironmentVariableContext context = environmentVariableContext();
    ArrayList<BuildCommand> commands = new ArrayList<>();
    commands.add(export("GO_SERVER_URL"));
    for (String property : context.getPropertyKeys()) {
        commands.add(export(property, context.getProperty(property), context.isPropertySecure(property)));
    }
    return BuildCommand.compose(commands);
}
Also used : ArrayList(java.util.ArrayList) BuildCommand(com.thoughtworks.go.domain.BuildCommand) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext)

Example 7 with EnvironmentVariableContext

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

the class JobInstanceSqlMapDaoTest method shouldLoadEnvironmentVariablesForScheduledJobs.

@Test
public void shouldLoadEnvironmentVariablesForScheduledJobs() {
    JobInstance newInstance = new JobInstance(JOB_NAME);
    newInstance.schedule();
    JobInstance instance = jobInstanceDao.save(stageId, newInstance);
    instance.setIdentifier(new JobIdentifier(savedPipeline, savedStage, instance));
    EnvironmentVariables variables = new EnvironmentVariables();
    variables.add("VARIABLE_NAME", "variable value");
    variables.add("TRIGGER_VAR", "junk val");
    JobPlan plan = new DefaultJobPlan(new Resources(), new ArrayList<>(), new ArrayList<>(), instance.getId(), instance.getIdentifier(), null, variables, new EnvironmentVariables(), null);
    jobInstanceDao.save(instance.getId(), plan);
    environmentVariableDao.save(savedPipeline.getId(), EnvironmentVariableType.Trigger, environmentVariables("TRIGGER_VAR", "trigger val"));
    List<JobPlan> retrieved = jobInstanceDao.orderedScheduledBuilds();
    JobPlan reloadedPlan = planForJob(retrieved, plan.getJobId());
    EnvironmentVariableContext context = new EnvironmentVariableContext();
    reloadedPlan.applyTo(context);
    assertThat(reloadedPlan.getVariables(), is(plan.getVariables()));
    assertThat(context.getProperty("VARIABLE_NAME"), is("variable value"));
    assertThat(context.getProperty("TRIGGER_VAR"), is("trigger val"));
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 8 with EnvironmentVariableContext

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

the class PackageMaterialTest method shouldPopulateEnvironmentContext.

@Test
public void shouldPopulateEnvironmentContext() {
    PackageMaterial material = new PackageMaterial();
    PackageRepository repository = PackageRepositoryMother.create("repo-id", "tw-dev", "pluginid", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1"), ConfigurationPropertyMother.create("repo-secure", true, "value")));
    material.setPackageDefinition(PackageDefinitionMother.create("p-id", "go-agent", new Configuration(ConfigurationPropertyMother.create("k2", false, "v2"), ConfigurationPropertyMother.create("pkg-secure", true, "value")), repository));
    material.setName(new CaseInsensitiveString("tw-dev:go-agent"));
    Modifications modifications = new Modifications(new Modification(null, null, null, new Date(), "revision-123"));
    EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
    material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null);
    assertThat(environmentVariableContext.getProperty("GO_REPO_TW_DEV_GO_AGENT_K1"), is("v1"));
    assertThat(environmentVariableContext.getProperty("GO_REPO_TW_DEV_GO_AGENT_REPO_SECURE"), is("value"));
    assertThat(environmentVariableContext.getPropertyForDisplay("GO_REPO_TW_DEV_GO_AGENT_REPO_SECURE"), is(EnvironmentVariableContext.EnvironmentVariable.MASK_VALUE));
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_K2"), is("v2"));
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_PKG_SECURE"), is("value"));
    assertThat(environmentVariableContext.getPropertyForDisplay("GO_PACKAGE_TW_DEV_GO_AGENT_PKG_SECURE"), is(EnvironmentVariableContext.EnvironmentVariable.MASK_VALUE));
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_LABEL"), is("revision-123"));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) Test(org.junit.Test)

Example 9 with EnvironmentVariableContext

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

the class EnvironmentVariableTest method addTo_shouldAddEnvironmentVariableToEnvironmentVariableContext.

@Test
public void addTo_shouldAddEnvironmentVariableToEnvironmentVariableContext() {
    final EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
    final EnvironmentVariable environmentVariable = new EnvironmentVariable("foo", "bar");
    environmentVariable.addTo(environmentVariableContext);
    verify(environmentVariableContext, times(1)).setProperty("foo", "bar", false);
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 10 with EnvironmentVariableContext

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

the class EnvironmentVariableTest method addToIfExists_shouldAddEnvironmentVariableToEnvironmentVariableContextWhenVariableIsAlreadyExistInContext.

@Test
public void addToIfExists_shouldAddEnvironmentVariableToEnvironmentVariableContextWhenVariableIsAlreadyExistInContext() {
    final EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
    final EnvironmentVariable environmentVariable = new EnvironmentVariable("foo", "bar");
    when(environmentVariableContext.hasProperty("foo")).thenReturn(true);
    environmentVariable.addToIfExists(environmentVariableContext);
    verify(environmentVariableContext, times(1)).setProperty("foo", "bar", false);
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) 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