Commits

mwent committed 2686a37

BDEV-1657 NUnitRunner task does not allow to customize environment before run

Comments (0)

Files changed (4)

src/main/java/com/atlassian/bamboo/plugin/dotnet/tests/nunit/NUnitRunnerConfigurator.java

             NUnitRunnerTaskType.TESTS_TO_RUN,
             NUnitRunnerTaskType.INCLUDED_TEST_CATEGORIES,
             NUnitRunnerTaskType.EXCLUDED_TEST_CATEGORIES,
-            NUnitRunnerTaskType.COMMAND_OPTIONS
+            NUnitRunnerTaskType.COMMAND_OPTIONS,
+            NUnitRunnerTaskType.ENVIRONMENT
     );
 
     @Override

src/main/java/com/atlassian/bamboo/plugin/dotnet/tests/nunit/NUnitRunnerTaskType.java

 import com.atlassian.bamboo.build.logger.interceptors.ErrorMemorisingInterceptor;
 import com.atlassian.bamboo.build.test.TestCollationService;
 import com.atlassian.bamboo.configuration.ConfigurationMap;
+import com.atlassian.bamboo.process.EnvironmentVariableAccessor;
 import com.atlassian.bamboo.process.ExternalProcessBuilder;
 import com.atlassian.bamboo.process.ProcessService;
 import com.atlassian.bamboo.task.TaskContext;
 import java.io.File;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Executes and parses test results from NUnit test runs executed via the command line.
     public static final String INCLUDED_TEST_CATEGORIES = "include"; // eg. /include:TheseTests,AndTheseTests
     public static final String EXCLUDED_TEST_CATEGORIES = "exclude"; // eg. /exclude:BrokenTests
     public static final String COMMAND_OPTIONS = "commandLineOptions";
+    public static final String ENVIRONMENT = "environmentVariables";
 
     // ------------------------------------------------------------------------------------------------- Type Properties
     // ---------------------------------------------------------------------------------------------------- Dependencies
     private final ProcessService processService;
     private final TestCollationService testCollationService;
     private final CapabilityContext capabilityContext;
+    private final EnvironmentVariableAccessor environmentVariableAccessor;
 
     // ---------------------------------------------------------------------------------------------------- Constructors
 
-    public NUnitRunnerTaskType(final ProcessService processService, final TestCollationService testCollationService, final CapabilityContext capabilityContext)
+    public NUnitRunnerTaskType(final ProcessService processService, final TestCollationService testCollationService, final CapabilityContext capabilityContext, final EnvironmentVariableAccessor environmentVariableAccessor)
     {
         this.processService = processService;
         this.testCollationService = testCollationService;
         this.capabilityContext = capabilityContext;
+        this.environmentVariableAccessor = environmentVariableAccessor;
     }
 
     // ----------------------------------------------------------------------------------------------- Interface Methods
                 command.add("-exclude=" + excludedCategories);
             }
 
+            final String environment = configuration.get(ENVIRONMENT);
+
+            final Map<String, String> env = environmentVariableAccessor.splitEnvironmentAssignments(environment);
+
             final String commandLineOptions = configuration.get(COMMAND_OPTIONS);
             if (StringUtils.isNotBlank(commandLineOptions))
             {
 
             final ExternalProcess externalProcess = processService.executeProcess(taskContext,
                                                                                   new ExternalProcessBuilder()
+                                                                                          .env(env)
                                                                                           .command(command)
                                                                                           .workingDirectory(taskContext.getWorkingDirectory()));
 

src/main/resources/com/atlassian/bamboo/plugin/dotnet/tests/nunit/nunitRunnerTaskEdit.ftl

 [@ww.textfield labelKey='nunit.includedCategories' name='include' cssClass="long-field" /]
 [@ww.textfield labelKey='nunit.excludedCategories' name='exclude' cssClass="long-field" /]
 [@ww.textfield labelKey='nunit.options' name='commandLineOptions' cssClass="long-field" /]
+[@ww.textfield labelKey='builder.common.env' name='environmentVariables' cssClass="long-field" /]
+

src/main/resources/com/atlassian/bamboo/plugin/dotnet/tests/nunit/nunitRunnerTaskView.ftl

 [@ww.label labelKey='nunit.testsToRun' name='run' /]
 [@ww.label labelKey='nunit.includedCategories' name='include' hideOnNull='true' /]
 [@ww.label labelKey='nunit.excludedCategories' name='exclude' hideOnNull='true' /]
-[@ww.label labelKey='nunit.options' name='options' hideOnNull='true' /]
+[@ww.label labelKey='nunit.options' name='options' hideOnNull='true' /]
+[@ww.label labelKey='builder.common.env' name='environmentVariables' hideOnNull='true' /]