提交 07198294 编写于 作者: K Kohsuke Kawaguchi

Merge branch 'pull-543'

......@@ -61,6 +61,9 @@ Upcoming changes</a>
<li class=bug>
Detect bugs relating to short <code>Descriptor</code> names early.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-14995">issue 14995</a> continued)
<li class=rfe>
Parameters defined in matrix projects are now available in configuration builds.
(<a href="https://github.com/jenkinsci/jenkins/pull/543">pull 543</a>)
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -2,6 +2,7 @@ package hudson.matrix;
import hudson.AbortException;
import hudson.Extension;
import hudson.Util;
import hudson.console.ModelHyperlinkNote;
import hudson.matrix.MatrixBuild.MatrixBuildExecution;
import hudson.matrix.listeners.MatrixBuildListener;
......@@ -194,10 +195,21 @@ public class DefaultMatrixExecutionStrategyImpl extends MatrixExecutionStrategy
return r;
}
/** Function to start schedule a single configuration
*
* This function schedule a build of a configuration passing all of the Matrixchild actions
* that are present in the parent build.
*
* @param exec Matrix build that is the parent of the configuration
* @param c Configuration to schedule
*/
private void scheduleConfigurationBuild(MatrixBuildExecution exec, MatrixConfiguration c) {
MatrixBuild build = exec.getBuild();
exec.getListener().getLogger().println(Messages.MatrixBuild_Triggering(ModelHyperlinkNote.encodeTo(c)));
c.scheduleBuild(build.getAction(ParametersAction.class), new UpstreamCause((Run)build));
// filter the parent actions for those that can be passed to the individual jobs.
List<MatrixChildAction> childActions = Util.filter(build.getActions(), MatrixChildAction.class);
c.scheduleBuild(childActions, new UpstreamCause((Run)build));
}
private MatrixRun waitForCompletion(MatrixBuildExecution exec, MatrixConfiguration c) throws InterruptedException, IOException {
......
/*
* The MIT License
*
* Copyright (c) 2012, Chris Johnson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.matrix;
import hudson.model.Action;
import hudson.model.Queue;
import hudson.model.Queue.Task;
/**
* Optional interface for {@link Action}s that are used as parameters
* to {@link Queue#schedule(Task, int, Action...)} to indicate that they
* want to be also passed to the {@link MatrixRun}s from its parent {@link MatrixBuild}.
*
* @author Chris Johnson
* @since 1.481
*/
public interface MatrixChildAction extends Action {
}
......@@ -53,6 +53,8 @@ import hudson.tasks.LogRotator;
import hudson.tasks.Publisher;
import java.io.IOException;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -359,13 +361,33 @@ public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun>
return scheduleBuild(parameters, new LegacyCodeCause());
}
/**
/** Starts the build with the ParametersAction that are passed in.
*
* @param parameters
* Can be null.
* @deprecated
* Use {@link #scheduleBuild(List<? extends Action>, Cause)}. Since 1.480
*/
public boolean scheduleBuild(ParametersAction parameters, Cause c) {
return Jenkins.getInstance().getQueue().schedule(this, getQuietPeriod(), parameters, new CauseAction(c), new ParentBuildAction())!=null;
return scheduleBuild(Collections.singletonList(parameters), c);
}
/**
* Starts the build with the actions that are passed in.
*
* @param actions Can be null.
* @param cause Reason for starting the build
*/
public boolean scheduleBuild(List<? extends Action> actions, Cause c) {
List<Action> allActions = new ArrayList<Action>();
if(actions != null)
allActions.addAll(actions);
allActions.add(new ParentBuildAction());
allActions.add(new CauseAction(c));
return Jenkins.getInstance().getQueue().schedule(this, getQuietPeriod(), allActions )!=null;
}
/**
......
......@@ -26,6 +26,7 @@ package hudson.model;
import hudson.Util;
import hudson.EnvVars;
import hudson.diagnosis.OldDataMonitor;
import hudson.matrix.MatrixChildAction;
import hudson.model.Queue.QueueAction;
import hudson.model.labels.LabelAssignmentAction;
import hudson.model.queue.SubTask;
......@@ -52,7 +53,7 @@ import java.util.Set;
* that were specified when scheduling.
*/
@ExportedBean
public class ParametersAction implements Action, Iterable<ParameterValue>, QueueAction, EnvironmentContributingAction, LabelAssignmentAction {
public class ParametersAction implements Action, Iterable<ParameterValue>, QueueAction, EnvironmentContributingAction, LabelAssignmentAction, MatrixChildAction {
private final List<ParameterValue> parameters;
......
......@@ -53,6 +53,13 @@ import hudson.model.FileParameterDefinition
import hudson.model.Cause.LegacyCodeCause
import hudson.model.ParametersAction
import hudson.model.FileParameterValue
import hudson.model.StringParameterDefinition
import hudson.model.StringParameterValue
import hudson.scm.SubversionSCM.SvnInfo;
import hudson.scm.RevisionParameterAction;
import java.util.List;
import java.util.ArrayList;
import hudson.model.Action;
import java.util.concurrent.CountDownLatch
......@@ -366,4 +373,62 @@ public class MatrixProjectTest extends HudsonTestCase {
assertEquals 4, dirs.size()
}
/**
* Test that Actions are passed to configurations
*/
public void testParameterActions() throws Exception {
MatrixProject p = createMatrixProject();
ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(
new StringParameterDefinition("PARAM_A","default_a"),
new StringParameterDefinition("PARAM_B","default_b"),
);
p.addProperty(pdp);
ParametersAction pa = new ParametersAction( pdp.getParameterDefinitions().collect { return it.getDefaultParameterValue() } )
MatrixBuild build = p.scheduleBuild2(0,new LegacyCodeCause(), pa).get();
assertEquals(4, build.getRuns().size());
for(MatrixRun run : build.getRuns()) {
ParametersAction pa1 = run.getAction(ParametersAction.class);
assertNotNull(pa1);
["PARAM_A","PARAM_B"].each{ assertNotNull(pa1.getParameter(it)) }
}
}
/**
* Test that other Actions are passed to configurations
* requires supported version of subversion plugin 1.43+
*/
//~ public void testMatrixChildActions() throws Exception {
//~ MatrixProject p = createMatrixProject();
//~ ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(
//~ new StringParameterDefinition("PARAM_A","default_a"),
//~ new StringParameterDefinition("PARAM_B","default_b"),
//~ );
//~ p.addProperty(pdp);
//~ List<Action> actions = new ArrayList<Action>();
//~ actions.add(new RevisionParameterAction(new SvnInfo("http://example.com/svn/repo/",1234)));
//~ actions.add(new ParametersAction( pdp.getParameterDefinitions().collect { return it.getDefaultParameterValue() } ));
//~ MatrixBuild build = p.scheduleBuild2(0,new LegacyCodeCause(), actions).get();
//~ assertEquals(4, build.getRuns().size());
//~ for(MatrixRun run : build.getRuns()) {
//~ ParametersAction pa1 = run.getAction(ParametersAction.class);
//~ assertNotNull(pa1);
//~ ["PARAM_A","PARAM_B"].each{ assertNotNull(pa1.getParameter(it)) };
//~ assertNotNull(run.getAction(RevisionParameterAction.class));
//~ }
//~ }
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册