From b2df57e4f08a7da5d03ee55e63635061bc379a0a Mon Sep 17 00:00:00 2001 From: kohsuke Date: Thu, 24 Jun 2010 00:47:03 +0000 Subject: [PATCH] [FIXED HUDSON-6497] slightly revised the patch, to avoid using a boolean flag for a concurrency control. It affects the serialization format, and it's not concurrency safe. Given the use case described in the bug, I wonder if it's better to have a different extension point (sort of like ComputerListener) that can contribute build variables to any builds going on in the system. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@32257 71c3de6d-444a-0410-be80-ed276b4c234a --- .../main/java/hudson/model/AbstractBuild.java | 7 +++++++ .../main/java/hudson/tasks/BuildWrapper.java | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index e4ca917027..319a3af134 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -740,6 +740,13 @@ public abstract class AbstractBuild

,R extends Abs if (v!=null) r.put(p.getName(),v); } } + + // allow the BuildWrappers to contribute additional build variables + if (project instanceof BuildableItemWithBuildWrappers) { + for (BuildWrapper bw : ((BuildableItemWithBuildWrappers) project).getBuildWrappersList()) + bw.makeBuildVariables(this,r); + } + return r; } diff --git a/core/src/main/java/hudson/tasks/BuildWrapper.java b/core/src/main/java/hudson/tasks/BuildWrapper.java index 75820e8ff8..0b01c9cc9a 100644 --- a/core/src/main/java/hudson/tasks/BuildWrapper.java +++ b/core/src/main/java/hudson/tasks/BuildWrapper.java @@ -33,6 +33,7 @@ import hudson.model.Run.RunnerAbortedException; import java.io.IOException; import java.util.Collection; import java.util.Collections; +import java.util.Map; /** * Pluggability point for performing pre/post actions for the build process. @@ -203,6 +204,22 @@ public abstract class BuildWrapper extends AbstractDescribableImpl return Collections.singletonList(a); } + /** + * Called to define {@linkplain AbstractBuild#getBuildVariables()}. + * + * This provides an opportunity for a BuildWrapper to append any additional + * build variables defined for the current build. + * + * @param build + * The build in progress for which this {@link BuildWrapper} is called. Never null. + * @param variables + * Contains existing build variables. Add additional build variables that you contribute + * to this map. + */ + public void makeBuildVariables(AbstractBuild build, Map variables) { + // noop + } + /** * Returns all the registered {@link BuildWrapper} descriptors. */ -- GitLab