Search in sources :

Example 81 with EnvironmentVariableContext

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

the class MaterialRevisionsTest method shouldPopulateEnvironmentVariablesForEachOfTheMaterialsWithTheValueForChangedFlag.

@Test
public void shouldPopulateEnvironmentVariablesForEachOfTheMaterialsWithTheValueForChangedFlag() {
    EnvironmentVariableContext context = new EnvironmentVariableContext();
    MaterialRevisions revisions = new MaterialRevisions();
    revisions.addRevision(new MaterialRevision(MaterialsMother.hgMaterial("empty-dest-and-no-name", null), true, ModificationsMother.multipleModificationList()));
    revisions.addRevision(new MaterialRevision(MaterialsMother.hgMaterial("url", "hg-folder1"), true, ModificationsMother.multipleModificationList()));
    revisions.addRevision(new MaterialRevision(MaterialsMother.hgMaterial("url", "hg-folder2"), false, ModificationsMother.multipleModificationList()));
    revisions.addRevision(new MaterialRevision(MaterialsMother.dependencyMaterial("p1", "s1"), true, ModificationsMother.changedDependencyMaterialRevision("p3", 1, "1", "s", 1, new Date()).getModifications()));
    revisions.addRevision(new MaterialRevision(MaterialsMother.dependencyMaterial("p2", "s2"), false, ModificationsMother.changedDependencyMaterialRevision("p3", 1, "1", "s", 1, new Date()).getModifications()));
    revisions.addRevision(new MaterialRevision(MaterialsMother.pluggableSCMMaterial("scm1", "scm1name"), true, ModificationsMother.multipleModificationList()));
    revisions.addRevision(new MaterialRevision(MaterialsMother.pluggableSCMMaterial("scm2", "scm2name"), false, ModificationsMother.multipleModificationList()));
    revisions.addRevision(new MaterialRevision(MaterialsMother.packageMaterial("repo1", "repo1name", "pkg1", "pkg1name"), true, ModificationsMother.multipleModificationList()));
    revisions.addRevision(new MaterialRevision(MaterialsMother.packageMaterial("repo2", "repo2name", "pkg2", "pkg2name"), false, ModificationsMother.multipleModificationList()));
    revisions.populateEnvironmentVariables(context, null);
    assertThat(context.getProperty("GO_MATERIAL_HAS_CHANGED"), is("true"));
    assertThat(context.getProperty("GO_MATERIAL_HG_FOLDER1_HAS_CHANGED"), is("true"));
    assertThat(context.getProperty("GO_MATERIAL_HG_FOLDER2_HAS_CHANGED"), is("false"));
    assertThat(context.getProperty("GO_MATERIAL_P1_HAS_CHANGED"), is("true"));
    assertThat(context.getProperty("GO_MATERIAL_P2_HAS_CHANGED"), is("false"));
    assertThat(context.getProperty("GO_MATERIAL_SCM1NAME_HAS_CHANGED"), is("true"));
    assertThat(context.getProperty("GO_MATERIAL_SCM2NAME_HAS_CHANGED"), is("false"));
    assertThat(context.getProperty("GO_MATERIAL_REPO1NAME_PKG1NAME_HAS_CHANGED"), is("true"));
    assertThat(context.getProperty("GO_MATERIAL_REPO2NAME_PKG2NAME_HAS_CHANGED"), is("false"));
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Date(java.util.Date) Test(org.junit.Test)

Example 82 with EnvironmentVariableContext

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

the class ProcessManagerTest method shouldAddToProcessListWhenNewProcessCreated.

@Test
public void shouldAddToProcessListWhenNewProcessCreated() {
    processManager.createProcess(new String[] { "echo", "message" }, "echo 'message'", null, new HashMap<>(), new EnvironmentVariableContext(), inMemoryConsumer(), "test-tag", "utf-8", "ERROR: ");
    assertThat(processManager.getProcessMap().size(), is(3));
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 83 with EnvironmentVariableContext

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

the class JobIdentifierTest method shouldPopulateGoJobInstanceRelatedEnvironmentVariables.

@Test
public void shouldPopulateGoJobInstanceRelatedEnvironmentVariables() {
    JobIdentifier id = new JobIdentifier("pipeline-name", 10, "label-10", "stage-name", "2", "build-name");
    id.setRerunOfCounter(1);
    EnvironmentVariableContext context = new EnvironmentVariableContext();
    id.populateEnvironmentVariables(context);
    EnvironmentVariableContext expected = new EnvironmentVariableContext();
    expected.setProperty("GO_PIPELINE_NAME", "pipeline-name", false);
    expected.setProperty("GO_PIPELINE_COUNTER", "10", false);
    expected.setProperty("GO_PIPELINE_LABEL", "label-10", false);
    expected.setProperty("GO_STAGE_NAME", "stage-name", false);
    expected.setProperty("GO_STAGE_COUNTER", "2", false);
    expected.setProperty("GO_RERUN_OF_STAGE_COUNTER", "1", false);
    expected.setProperty("GO_JOB_NAME", "build-name", false);
    assertThat(context, is(expected));
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 84 with EnvironmentVariableContext

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

the class JobIdentifierTest method shouldNotPopulate_RerunOfStage_whenNotAvailable.

@Test
public void shouldNotPopulate_RerunOfStage_whenNotAvailable() {
    JobIdentifier id = new JobIdentifier("pipeline-name", 10, "label-10", "stage-name", "2", "build-name");
    EnvironmentVariableContext context = new EnvironmentVariableContext();
    id.populateEnvironmentVariables(context);
    assertThat(context.hasProperty("GO_RERUN_OF_STAGE_COUNTER"), is(false));
    id.setRerunOfCounter(1);
    context = new EnvironmentVariableContext();
    id.populateEnvironmentVariables(context);
    assertThat(context.hasProperty("GO_RERUN_OF_STAGE_COUNTER"), is(true));
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 85 with EnvironmentVariableContext

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

the class BuildComposer method environmentVariableContext.

private EnvironmentVariableContext environmentVariableContext() {
    EnvironmentVariableContext context = new EnvironmentVariableContext();
    context.addAll(assignment.initialEnvironmentVariableContext());
    return context;
}
Also used : 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