Search in sources :

Example 91 with EnvironmentVariableContext

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

the class PackageMaterial method populateEnvironmentContext.

@Override
public void populateEnvironmentContext(EnvironmentVariableContext context, MaterialRevision materialRevision, File workingDir) {
    context.setProperty(upperCase(format("GO_PACKAGE_%s_LABEL", escapeEnvironmentVariable(getName().toString()))), materialRevision.getRevision().getRevision(), false);
    for (ConfigurationProperty configurationProperty : getPackageDefinition().getRepository().getConfiguration()) {
        context.setProperty(getEnvironmentVariableKey("GO_REPO_%s_%s", configurationProperty.getConfigurationKey().getName()), configurationProperty.getValue(), configurationProperty.isSecure());
    }
    for (ConfigurationProperty configurationProperty : getPackageDefinition().getConfiguration()) {
        context.setProperty(getEnvironmentVariableKey("GO_PACKAGE_%s_%s", configurationProperty.getConfigurationKey().getName()), configurationProperty.getValue(), configurationProperty.isSecure());
    }
    HashMap<String, String> additionalData = materialRevision.getLatestModification().getAdditionalDataMap();
    if (additionalData != null) {
        for (Map.Entry<String, String> entry : additionalData.entrySet()) {
            boolean isSecure = false;
            for (EnvironmentVariableContext.EnvironmentVariable secureEnvironmentVariable : context.getSecureEnvironmentVariables()) {
                String urlEncodedValue = null;
                try {
                    urlEncodedValue = URLEncoder.encode(secureEnvironmentVariable.value(), "UTF-8");
                } catch (UnsupportedEncodingException e) {
                }
                boolean isSecureEnvironmentVariableEncoded = !StringUtils.isBlank(urlEncodedValue) && !secureEnvironmentVariable.value().equals(urlEncodedValue);
                if (isSecureEnvironmentVariableEncoded && entry.getValue().contains(urlEncodedValue)) {
                    isSecure = true;
                    break;
                }
            }
            String key = entry.getKey();
            String value = entry.getValue();
            context.setProperty(getEnvironmentVariableKey("GO_PACKAGE_%s_%s", key), value, isSecure);
        }
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) HashMap(java.util.HashMap) Map(java.util.Map)

Example 92 with EnvironmentVariableContext

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

the class JobInstanceSqlMapDaoTest method shouldSaveEnvironmentVariables.

@Test
public void shouldSaveEnvironmentVariables() {
    JobInstance instance = jobInstanceDao.save(stageId, new JobInstance(JOB_NAME));
    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"));
    JobPlan retrieved = jobInstanceDao.loadPlan(plan.getJobId());
    assertThat(retrieved.getVariables(), is(plan.getVariables()));
    EnvironmentVariableContext context = new EnvironmentVariableContext();
    retrieved.applyTo(context);
    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 93 with EnvironmentVariableContext

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

the class AntTaskBuilderTest method shouldFailWhenTargetDoesNotExist.

@Test
public void shouldFailWhenTargetDoesNotExist() {
    String target = "not-exist-target";
    String buildXml = "./build.xml";
    antTask.setBuildFile(buildXml);
    antTask.setTarget(target);
    Builder builder = antTaskBuilder.createBuilder(builderFactory, antTask, TasksTest.pipelineStub(PIPELINE_LABEL, "."), resolver);
    try {
        builder.build(new StubGoPublisher(), new EnvironmentVariableContext(), taskEntension, null, null, "utf-8");
    } catch (CruiseControlException e) {
        assertThat(e.getMessage(), containsString("Build failed. Command ant reported [BUILD FAILED]."));
    }
}
Also used : StubGoPublisher(com.thoughtworks.go.domain.StubGoPublisher) CruiseControlException(com.thoughtworks.go.util.command.CruiseControlException) CommandBuilder(com.thoughtworks.go.domain.builder.CommandBuilder) Builder(com.thoughtworks.go.domain.builder.Builder) StringContains.containsString(org.hamcrest.core.StringContains.containsString) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test) TasksTest(com.thoughtworks.go.domain.TasksTest)

Example 94 with EnvironmentVariableContext

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

the class KillAllChildProcessTaskBuilderTest method shouldKillAllChildProcessOnbuild.

// 11 minutes
@Test(timeout = 11 * 60 * 1000)
public void shouldKillAllChildProcessOnbuild() throws Exception {
    ProcessWrapper processWrapper = CommandLine.createCommandLine("sleep").withArg(String.valueOf(10 * 60)).withEncoding("utf-8").execute(ProcessOutputStreamConsumer.inMemoryConsumer(), new EnvironmentVariableContext(), // 60 mins
    null);
    assertThat(processWrapper.isRunning(), is(true));
    DefaultGoPublisher publisher = mock(DefaultGoPublisher.class);
    EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
    long before = getSystemTime();
    Builder builder = new KillAllChildProcessTaskBuilder().createBuilder(builderFactory, new KillAllChildProcessTask(), null, null);
    builder.build(publisher, environmentVariableContext, null, null, null, "utf-8");
    assertThat(processWrapper.waitForExit(), is(greaterThan(0)));
    // min = 10; sec = 60*min; mills = 1000*sec; micro = 1000*mills; nano = 1000*micro;
    assertThat(getSystemTime() - before, is(lessThan(10 * 60 * 1000 * 1000 * 1000L)));
}
Also used : ProcessWrapper(com.thoughtworks.go.util.ProcessWrapper) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) Builder(com.thoughtworks.go.domain.builder.Builder) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) KillAllChildProcessTask(com.thoughtworks.go.domain.KillAllChildProcessTask) 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