Skip to content
Permalink
Browse files

Fix JENKINS-16575 and JENKINS-16566

  • Loading branch information
gboissinot committed Feb 3, 2013
1 parent ba4c580 commit e0585e40a9022653693902a6449de2611db71447
Showing with 43 additions and 6 deletions.
  1. +43 −6 src/main/java/org/jenkinsci/lib/envinject/EnvInjectAction.java
@@ -34,11 +34,31 @@ public EnvInjectAction(AbstractBuild build, Map<String, String> envMap) {
}

public void overrideAll(Map<String, String> all) {
if (envMap == null) {
return;
}

if (all == null) {
return;
}

envMap.putAll(all);
}

@SuppressWarnings({"unused", "unchecked"})
public Map<String, String> getEnvMap() {
if (envMap == null) {

//Try to fill the envMap from the build injected environment
//file (injectedEnvVars.txt by default).
try {
envMap = getEnvironment(build);
} catch (EnvInjectException e) {
return null;
}
return envMap;
}

return UnmodifiableMap.decorate(envMap);
}

@@ -72,6 +92,24 @@ private Object writeReplace() throws ObjectStreamException {
return this;
}


private Map<String, String> getEnvironment(AbstractBuild build) throws EnvInjectException {

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

AbstractProject project = build.getProject();
if (project == null) {
return null;
}

EnvInjectSavable dao = new EnvInjectSavable();
File rootDir = new File(project.getRootDir(), build.getId());
return dao.getEnvironment(rootDir);
}


@SuppressWarnings("unused")
private Object readResolve() throws ObjectStreamException {

@@ -80,21 +118,20 @@ private Object readResolve() throws ObjectStreamException {
return this;
}

EnvInjectSavable dao = new EnvInjectSavable();
Map<String, String> resultMap = null;
try {
if (build != null) {
AbstractProject project = build.getProject();
if (project != null) {
File rootDir = new File(project.getRootDir(), build.getId());
resultMap = dao.getEnvironment(rootDir);
}
return getEnvironment(build);
} else if (rootDir != null) {
EnvInjectSavable dao = new EnvInjectSavable();
resultMap = dao.getEnvironment(rootDir);
}


if (resultMap != null) {
envMap = resultMap;
}

} catch (Throwable e) {
e.printStackTrace();
}

0 comments on commit e0585e4

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