mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-18 06:22:29 +00:00
code simplification. Parameterized build is in the core, so we should make AbstractBuild aware of it.
See http://www.nabble.com/TFS-build-by-label--td21859630.html where Eric mentioned his confusion about how his plugin can get parameters. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15091 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
6ee24ace94
commit
1f11a93393
5 files changed
+25
-10
No files matched your search
@@ -98,8 +98,10 @@ public class MatrixRun extends Build<MatrixConfiguration,MatrixRun> {
|
||||
|
||||
@Override
|
||||
public Map<String,String> getBuildVariables() {
|
||||
Map<String,String> r = super.getBuildVariables();
|
||||
// pick up user axes
|
||||
return new HashMap<String,String>(getParent().getCombination());
|
||||
r.putAll(getParent().getCombination());
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,6 +45,7 @@ import hudson.tasks.test.AbstractTestResultAction;
|
||||
import hudson.util.AdaptedIterator;
|
||||
import hudson.util.Iterators;
|
||||
import hudson.util.VariableResolver;
|
||||
import hudson.util.VariableResolver.ByMap;
|
||||
import org.kohsuke.stapler.Stapler;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
@@ -451,10 +452,24 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
|
||||
* {@link Builder}s to decide whether it wants to recognize the values
|
||||
* or how to use them.
|
||||
*
|
||||
* ugly ugly hack.
|
||||
* <p>
|
||||
* This also includes build parameters if a build is parameterized.
|
||||
*
|
||||
* @return
|
||||
* The returned map is mutable so that subtypes can put more values.
|
||||
*/
|
||||
public Map<String,String> getBuildVariables() {
|
||||
return Collections.emptyMap();
|
||||
Map<String,String> r = new HashMap<String, String>();
|
||||
|
||||
ParametersAction parameters = getAction(ParametersAction.class);
|
||||
if(parameters!=null) {
|
||||
// this is a rather round about way of doing this...
|
||||
for (ParameterValue p : parameters) {
|
||||
String v = p.createVariableResolver(this).resolve(p.getName());
|
||||
if(v!=null) r.put(p.getName(),v);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@ package hudson.model;
|
||||
|
||||
import hudson.Util;
|
||||
import hudson.tasks.BuildWrapper;
|
||||
import hudson.tasks.BuildStep;
|
||||
import hudson.util.VariableResolver;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -70,6 +71,9 @@ public class ParametersAction implements Action, Iterable<ParameterValue> {
|
||||
|
||||
/**
|
||||
* Creates an {@link VariableResolver} that aggregates all the parameters.
|
||||
*
|
||||
* <p>
|
||||
* If you are a {@link BuildStep}, most likely you should call {@link AbstractBuild#getBuildVariableResolver()}.
|
||||
*/
|
||||
public VariableResolver<String> createVariableResolver(AbstractBuild<?,?> build) {
|
||||
VariableResolver[] resolvers = new VariableResolver[parameters.size()+1];
|
||||
|
||||
@@ -167,10 +167,7 @@ public class Ant extends Builder {
|
||||
args.addKeyValuePairs("-D",build.getBuildVariables());
|
||||
|
||||
VariableResolver<String> vr = build.getBuildVariableResolver();
|
||||
ParametersAction parameters = build.getAction(ParametersAction.class);
|
||||
if(parameters!=null)
|
||||
vr = parameters.createVariableResolver(build);
|
||||
|
||||
|
||||
args.addKeyValuePairsFromPropertyString("-D",properties,vr);
|
||||
|
||||
args.addTokenized(Util.replaceMacro(targets,vr).replaceAll("[\t\r\n]+"," "));
|
||||
|
||||
@@ -177,9 +177,6 @@ public class Maven extends Builder {
|
||||
AbstractProject proj = build.getProject();
|
||||
|
||||
VariableResolver<String> vr = build.getBuildVariableResolver();
|
||||
ParametersAction parameters = build.getAction(ParametersAction.class);
|
||||
if(parameters!=null)
|
||||
vr = parameters.createVariableResolver(build);
|
||||
|
||||
String targets = Util.replaceMacro(this.targets,vr);
|
||||
|
||||
|
||||
Reference in new issue
Block a user