diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index d62f427289..42a46999b5 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -844,27 +844,26 @@ public abstract class AbstractBuild
,R extends Abs /** * During the build, expose the environments contributed by {@link BuildWrapper}s and others. - * + * + *
+ * Since 1.444, executor thread that's doing the build can access mutable underlying list,
+ * which allows the caller to add/remove environments. The recommended way of adding
+ * environment is through {@link BuildWrapper}, but this might be handy for build steps
+ * who wants to expose additional environment variables to the rest of the build.
+ *
* @return can be empty list, but never null. Immutable.
* @since 1.437
*/
public EnvironmentList getEnvironments() {
+ Executor e = Executor.currentExecutor();
+ if (e!=null && e.getCurrentExecutable()==this) {
+ if (buildEnvironments==null) buildEnvironments = new ArrayList
- * For concurrency, this method is only designed to be called from the executor that's doing a build,
- * during the build.
- *
- * @since 1.444
- */
- public void addEnvironment(Environment env) {
- if (env!=null)
- buildEnvironments.add(env);
- }
-
public Calendar due() {
return getTimestamp();
}
diff --git a/core/src/main/java/hudson/model/EnvironmentList.java b/core/src/main/java/hudson/model/EnvironmentList.java
index 67918a3e0a..1c1b07a205 100644
--- a/core/src/main/java/hudson/model/EnvironmentList.java
+++ b/core/src/main/java/hudson/model/EnvironmentList.java
@@ -56,4 +56,19 @@ public final class EnvironmentList extends AbstractList