Skip to content
Permalink
Browse files

[JENKINS-46479] Prevent environment variables from being deleted on e…

…xisting builds (#11)

* Load env vars from disk before saving so they aren't deleted if the cached value is wrong

* Revert "Load env vars from disk before saving so they aren't deleted if the cached value is wrong"

I think it is better to have onLoad intialize envMap and keep writeReplace the same. This reverts commit dab1c21.

* Set envMap after the build is set in onLoad

* Revert "Set envMap after the build is set in onLoad"

This reverts commit faa9873.

* Revert "Revert "Load env vars from disk before saving so they aren't deleted if the cached value is wrong""

This reverts commit 01dee1a.

* Cache the result of getEnvMap so we don't keep loading from disk
  • Loading branch information...
dwnusbaum authored and oleg-nenashev committed Oct 6, 2017
1 parent ab17eee commit f4386942fc8a32d65f99fd974b9d337ecc508cfb
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/main/java/org/jenkinsci/lib/envinject/EnvInjectAction.java
@@ -12,6 +12,7 @@
import java.io.File;
import java.io.ObjectStreamException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
@@ -104,6 +105,10 @@ public void overrideAll(
//file (injectedEnvVars.txt by default).
try {
Map<String, String> result = getEnvironment(build);
if (build != null && build.getParent() != null) {
// Cache the result so we don't keep loading the environment from disk.
envMap = result == null ? new HashMap<String, String>(0) : result;
}
return result == null ? null : UnmodifiableMap.decorate(result);
} catch (EnvInjectException e) {
return null;
@@ -130,8 +135,11 @@ private Object writeReplace() throws ObjectStreamException {
try {
EnvInjectSavable dao = new EnvInjectSavable();

Map<String, String> toWrite = envMap != null ? envMap : Collections.<String, String>emptyMap();

Map<String, String> toWrite = getEnvMap();
if (toWrite == null) {
toWrite = Collections.<String, String>emptyMap();
}

if (rootDir == null) {
dao.saveEnvironment(build.getRootDir(), Maps.transformEntries(toWrite,
new Maps.EntryTransformer<String, String, String>() {

0 comments on commit f438694

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