Skip to content
Permalink
Browse files

Fix JENKINS-14930

  • Loading branch information...
gboissinot committed Aug 30, 2012
1 parent 952af19 commit 9abab6b3d9a7c6c8850dc1ac33d7976aab5ac718
Showing with 41 additions and 3 deletions.
  1. +41 −3 src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectEnvVars.java
@@ -6,6 +6,7 @@
import hudson.Util;
import hudson.model.BuildListener;
import hudson.model.Hudson;
import hudson.util.VariableResolver;
import org.jenkinsci.lib.envinject.EnvInjectException;
import org.jenkinsci.lib.envinject.EnvInjectLogger;

@@ -197,17 +198,54 @@ public void resolveVars(Map<String, String> variables, Map<String, String> env)
private Map<String, String> removeUnsetVars(Map<String, String> envVars) {
Map<String, String> result = new HashMap<String, String>();
for (Map.Entry<String, String> entry : envVars.entrySet()) {
if (!isUnresolvedVar(entry.getValue())) {
result.put(entry.getKey(), removeEscapeDollar(entry.getValue()));

String value = entry.getValue();

value = removeUnsetVars(value);

if (!isUnresolvedVar(value)) {
result.put(entry.getKey(), removeEscapeDollar(value));
} else {
logger.info(String.format("Unset unresolved '%s' variable.", entry.getKey()));
}
}
return result;
}

private String removeUnsetVars(String value) {

if (value == null) {
return null;
}

if (value.length() == 0) {
return value;
}

if (!value.contains("$") || value.contains("\\$")) {
return value;
}

return Util.replaceMacro(value, new VariableResolver<String>() {

public String resolve(String name) {
return "";
}
});

}

private boolean isUnresolvedVar(String value) {
return value != null && value.contains("$") && !value.contains("\\$");

if (value == null) {
return true;
}

if (value.trim().length() == 0) {
return true;
}

return value.contains("$") && !value.contains("\\$");
}

private String removeEscapeDollar(String value) {

0 comments on commit 9abab6b

Please sign in to comment.
You can’t perform that action at this time.