package com.codicesoftware.plugins.hudson.util;

import hudson.EnvVars;
import hudson.Util;
import hudson.model.ParameterValue;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SelectorParametersResolver {

    private SelectorParametersResolver() { }

    public static String resolve(String text, List<ParameterValue> parameters, EnvVars environment) {
        if (parameters == null) {
            return text;
        }

        Map<String, String> parametersMap = new HashMap<>();
        for (ParameterValue parameter : parameters) {
            if ((parameter != null) && (parameter.getName() != null) && (parameter.getValue() != null)) {
                parametersMap.put(parameter.getName(), parameter.getValue().toString());
            }
        }

        return environment.expand(Util.replaceMacro(
            resolveLegacyFormat(text, parametersMap), parametersMap));
    }

    static String resolveLegacyFormat(String text, Map<String, String> parametersMap) {
        String result = text;
        for (Map.Entry<String, String> entry : parametersMap.entrySet()) {
            result = result.replaceAll("%" + entry.getKey() + "%", entry.getValue());
        }
        return result;
    }
}

package com.codicesoftware.plugins.hudson.util;

import hudson.Util;
import hudson.model.ParameterValue;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SelectorParametersResolver {

    private SelectorParametersResolver() { }

    public static String resolve(String text, List<ParameterValue> parameters) {
        if (parameters == null) {
            return text;
        }

        Map<String, String> parametersMap = new HashMap<>();
        for (ParameterValue parameter : parameters) {
            if ((parameter != null) && (parameter.getName() != null) && (parameter.getValue() != null)) {
                parametersMap.put(parameter.getName(), parameter.getValue().toString());
            }
        }

        return Util.replaceMacro(
                resolveLegacyFormat(text, parametersMap), parametersMap);
    }

    static String resolveLegacyFormat(String text, Map<String, String> parametersMap) {
        String result = text;
        for (Map.Entry<String, String> entry : parametersMap.entrySet()) {
            result = result.replaceAll("%" + entry.getKey() + "%", entry.getValue());
        }
        return result;
    }
}

--- 
+++ 
@@ -1,5 +1,6 @@
 package com.codicesoftware.plugins.hudson.util;
 
+import hudson.EnvVars;
 import hudson.Util;
 import hudson.model.ParameterValue;
 
@@ -11,7 +12,7 @@
 
     private SelectorParametersResolver() { }
 
-    public static String resolve(String text, List<ParameterValue> parameters) {
+    public static String resolve(String text, List<ParameterValue> parameters, EnvVars environment) {
         if (parameters == null) {
             return text;
         }
@@ -23,8 +24,8 @@
             }
         }
 
-        return Util.replaceMacro(
-                resolveLegacyFormat(text, parametersMap), parametersMap);
+        return environment.expand(Util.replaceMacro(
+            resolveLegacyFormat(text, parametersMap), parametersMap));
     }
 
     static String resolveLegacyFormat(String text, Map<String, String> parametersMap) {
Expand environment variables when resolving parameters in selector

Signed-off-by: Miguel González <967cccf84fe94e619b35e1dff246b8b33dcf8eed@unity3d.com>
