Search in sources :

Example 56 with EnvironmentVariableContext

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

the class BuildAssignmentTest method shouldInitializeEnvironmentContextFromJobPlan.

@Test
public void shouldInitializeEnvironmentContextFromJobPlan() throws Exception {
    DefaultJobPlan defaultJobPlan = jobForPipeline("foo");
    EnvironmentVariables variables = new EnvironmentVariables();
    variables.add("key1", "value1");
    variables.add("key2", "value2");
    defaultJobPlan.setVariables(variables);
    BuildAssignment buildAssignment = BuildAssignment.create(defaultJobPlan, BuildCause.createManualForced(), new ArrayList<>(), null, null, new ArtifactStores());
    EnvironmentVariableContext context = buildAssignment.initialEnvironmentVariableContext();
    assertThat(context.getProperties().size(), is(9));
    assertThat(context.getProperty("key1"), is("value1"));
    assertThat(context.getProperty("key2"), is("value2"));
}
Also used : ArtifactStores(com.thoughtworks.go.config.ArtifactStores) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 57 with EnvironmentVariableContext

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

the class BuildWorkArtifactUploadingTest method createAssignment.

private BuildAssignment createAssignment(List<ArtifactPlan> artifactPlans, String[] fileToCreate) throws IOException {
    MaterialRevisions materialRevisions = materialRevisions();
    BuildCause buildCause = BuildCause.createWithModifications(materialRevisions, "");
    List<Builder> builders = new ArrayList<>();
    builders.add(new CreateFileBuilder(fileToCreate));
    DefaultJobPlan plan = new DefaultJobPlan(new Resources(), artifactPlans, new ArrayList<>(), -1, new JobIdentifier(PIPELINE_NAME, -2, "1", STAGE_NAME, "1", JOB_NAME), null, new EnvironmentVariables(), new EnvironmentVariables(), null);
    return BuildAssignment.create(plan, buildCause, builders, buildWorkingDirectory, new EnvironmentVariableContext(), new ArtifactStores());
}
Also used : ArtifactStores(com.thoughtworks.go.config.ArtifactStores) Builder(com.thoughtworks.go.domain.builder.Builder) NullBuilder(com.thoughtworks.go.domain.builder.NullBuilder) ArrayList(java.util.ArrayList) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext)

Example 58 with EnvironmentVariableContext

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

the class BuildWorkArtifactUploadingTest method setUp.

@Before
public void setUp() throws IOException {
    initMocks(this);
    buildWorkingDirectory = new File("tmp" + UUID.randomUUID());
    environmentVariableContext = new EnvironmentVariableContext();
    svnRepoFixture = new SvnRepoFixture("../common/src/test/resources/data/svnrepo", temporaryFolder);
    svnRepoFixture.createRepository();
    SvnCommand command = new SvnCommand(null, svnRepoFixture.getEnd2EndRepoUrl());
    PipelineConfigMother.createPipelineConfig(PIPELINE_NAME, STAGE_NAME, JOB_NAME);
    svnMaterial = SvnMaterial.createSvnMaterialWithMock(command);
    new SystemEnvironment().setProperty("serviceUrl", "some_random_place");
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) SvnCommand(com.thoughtworks.go.domain.materials.svn.SvnCommand) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) File(java.io.File) SvnRepoFixture(com.thoughtworks.go.utils.SvnRepoFixture) Before(org.junit.Before)

Example 59 with EnvironmentVariableContext

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

the class BuildWorkEnvironmentVariablesTest method shouldSetUpEnvironmentContextCorrectly.

@Test
public void shouldSetUpEnvironmentContextCorrectly() throws Exception {
    new SystemEnvironment().setProperty("serviceUrl", "some_random_place");
    Materials materials = new Materials(svnMaterial);
    EnvironmentVariableContext environmentVariableContext = doWorkWithMaterials(materials);
    assertThat(environmentVariableContext.getProperty("GO_REVISION"), is("3"));
    assertThat(environmentVariableContext.getProperty("GO_SERVER_URL"), is("some_random_place"));
    assertThat(environmentVariableContext.getProperty("GO_PIPELINE_NAME"), is(PIPELINE_NAME));
    assertThat(environmentVariableContext.getProperty("GO_PIPELINE_LABEL"), is("1"));
    assertThat(environmentVariableContext.getProperty("GO_STAGE_NAME"), is(STAGE_NAME));
    assertThat(environmentVariableContext.getProperty("GO_STAGE_COUNTER"), is("1"));
    assertThat(environmentVariableContext.getProperty("GO_JOB_NAME"), is(JOB_NAME));
    assertThat(environmentVariableContext.getProperty("GO_TRIGGER_USER"), is(TRIGGERED_BY_USER));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Materials(com.thoughtworks.go.config.materials.Materials) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 60 with EnvironmentVariableContext

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

the class BuildWorkEnvironmentVariablesTest method doWorkWithMaterials.

private EnvironmentVariableContext doWorkWithMaterials(Materials materials) throws IOException {
    pipelineConfig.setMaterialConfigs(materials.convertToConfigs());
    BuildAssignment buildAssigment = createAssignment(null);
    BuildWork work = new BuildWork(buildAssigment, systemEnvironment.consoleLogCharset());
    EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
    AgentIdentifier agentIdentifier = new AgentIdentifier("somename", "127.0.0.1", AGENT_UUID);
    work.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, new FakeBuildRepositoryRemote(), new GoArtifactsManipulatorStub(), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension, null, null));
    return environmentVariableContext;
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) FakeBuildRepositoryRemote(com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext)

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