Skip to content
Permalink
Browse files

Improved to work with jobs deeper down in the tree.

  • Loading branch information
kohsuke committed Feb 9, 2012
1 parent 830cf99 commit 693c20eb1140d77e7dd1075fa52a0164fc4667f1
@@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.398</version>
<version>1.424</version>
</parent>

<artifactId>parameterized-trigger</artifactId>
@@ -68,7 +68,7 @@ public void buildDependencyGraph(AbstractProject owner, DependencyGraph graph) {
if (!canDeclare(owner)) return;

for (BuildTriggerConfig config : configs)
for (AbstractProject project : config.getProjectList(null))
for (AbstractProject project : config.getProjectList(owner.getParent(),null))
ParameterizedDependency.add(owner, project, config, graph);
}

@@ -18,6 +18,7 @@
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.model.Items;
import hudson.model.Job;
import hudson.model.ParameterDefinition;
@@ -29,6 +30,8 @@
import hudson.plugins.parameterizedtrigger.AbstractBuildParameters.DontTriggerException;
import hudson.tasks.Messages;
import hudson.util.FormValidation;

import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -104,10 +107,20 @@ public boolean getTriggerWithNoParameters() {
return triggerWithNoParameters;
}

/**
* @deprecated
* Use {@link #getProjectList(ItemGroup, EnvVars)}
*/
public List<AbstractProject> getProjectList(EnvVars env) {
return getProjectList(null,env);
}

/**
* @param env Environment variables from which to expand project names; Might be {@code null}.
* @param context
* The container with which to resolve relative project names.
*/
public List<AbstractProject> getProjectList(EnvVars env) {
public List<AbstractProject> getProjectList(ItemGroup context, EnvVars env) {
if(projectList == null) {
projectList = new ArrayList<AbstractProject>();

@@ -121,7 +134,7 @@ public boolean getTriggerWithNoParameters() {
projectNames.append(env != null ? env.expand(tokens.nextToken().trim()) : tokens.nextToken().trim());
}

projectList.addAll(Items.fromNameList(projectNames.toString(), AbstractProject.class));
projectList.addAll(Items.fromNameList(context, projectNames.toString(), AbstractProject.class));
}
return projectList;
}
@@ -206,7 +219,7 @@ private static ParametersAction getDefaultParameters(AbstractProject<?,?> projec
List<Action> actions = getBaseActions(
ImmutableList.<AbstractBuildParameters>builder().addAll(configs).addAll(addConfigs).build(),
build, listener);
for (AbstractProject project : getProjectList(env)) {
for (AbstractProject project : getProjectList(build.getProject().getParent(),env)) {
List<Action> list = getBuildActions(actions, project);

futures.add(schedule(build, project, list));
@@ -231,7 +244,7 @@ private static ParametersAction getDefaultParameters(AbstractProject<?,?> projec

for (List<AbstractBuildParameters> addConfigs : getDynamicBuildParameters(build, listener)) {
List<Action> actions = getBaseActions(ImmutableList.<AbstractBuildParameters>builder().addAll(configs).addAll(addConfigs).build(), build, listener);
for (AbstractProject project : getProjectList(env)) {
for (AbstractProject project : getProjectList(build.getProject().getParent(),env)) {
List<Action> list = getBuildActions(actions, project);

futures.put(project, schedule(build, project, list));
@@ -349,8 +362,7 @@ public FormValidation doCheckProjects(@AncestorInPath Item project, @QueryParame
while(tokens.hasMoreTokens()) {
String projectName = tokens.nextToken().trim();
if (StringUtils.isNotBlank(projectName)) {
//Item item = Jenkins.getInstance().getItem(projectName,project,Item.class); // only works after version 1.410
Item item = Hudson.getInstance().getItem(projectName);
Item item = Jenkins.getInstance().getItem(projectName,project,Item.class); // only works after version 1.410
if(item==null){
return FormValidation.error(Messages.BuildTrigger_NoSuchProject(projectName,AbstractProject.findNearest(projectName).getName()));
}
@@ -94,8 +94,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
try {
for (BlockableBuildTriggerConfig config : configs) {
ListMultimap<AbstractProject, Future<AbstractBuild>> futures = config.perform2(build, launcher, listener);
List<AbstractProject> projectList = config.getProjectList(env);
List<AbstractProject> projectList = config.getProjectList(build.getProject().getParent(),env);

if(!projectList.isEmpty()){
//handle non-blocking configs
if(futures.isEmpty()){
@@ -135,7 +135,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
@Override
public void buildDependencyGraph(AbstractProject owner, DependencyGraph graph) {
for (BuildTriggerConfig config : configs)
for (AbstractProject project : config.getProjectList(null))
for (AbstractProject project : config.getProjectList(owner.getParent(),null))
graph.addDependency(new ParameterizedDependency(owner, project, config) {
@Override
public boolean shouldTriggerBuild(AbstractBuild build,

0 comments on commit 693c20e

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