Skip to content
Permalink
Browse files
[JENKINS-22808] Add support for parameterized jobs trigger nested in …
…flexible publisher
  • Loading branch information
syl20bnr committed Apr 29, 2014
1 parent 67e8779 commit a492fad53958b4202e5414f3cc5b88a5de7941e4
Showing 1 changed file with 55 additions and 30 deletions.
@@ -80,6 +80,8 @@ of this software and associated documentation files (the "Software"), to deal
import org.dom4j.VisitorSupport;
import org.dom4j.io.SAXReader;

import org.jenkins_ci.plugins.flexible_publish.ConditionalPublisher;
import org.jenkins_ci.plugins.flexible_publish.FlexiblePublisher;
import org.jenkins_ci.plugins.run_condition.RunCondition;
import org.jenkinsci.plugins.conditionalbuildstep.singlestep.SingleConditionalBuilder;
import org.jenkinsci.plugins.jobgenerator.actions.*;
@@ -472,36 +474,6 @@ private void gatherDownstreamGenerators(BuildListener listener)
new ArrayList<AbstractProject>();
List<ParametersAction> lpa = getBuild().getActions(
hudson.model.ParametersAction.class);
// parameterized build trigger build trigger
BuildTrigger bt = job.getPublishersList().get(BuildTrigger.class);
if (bt != null) {
for (ListIterator<BuildTriggerConfig> btc =
bt.getConfigs().listIterator(); btc.hasNext();) {
BuildTriggerConfig c = btc.next();
for (AbstractProject p : c.getProjectList(job.getParent(),
null)) {
List<List<ParametersAction>> importParams =
new ArrayList<List<ParametersAction>>();
importParams.add(new ArrayList<ParametersAction>());
importParams.get(0).addAll(lpa);
List<AbstractBuildParameters> lbp = c.getConfigs();
for(AbstractBuildParameters bp: lbp){
if(bp.getClass().getSimpleName().equals(
"PredefinedGeneratorParameters")){
importParams.get(0).add((ParametersAction)
bp.getAction(GeneratorRun.this, listener));
}
}
if (JobGenerator.class.isInstance(p)){
job.copyOptions((JobGenerator) p);
downstreamGenerators.add(
new DownstreamGenerator(p, importParams));
processedProjects.add(p);
}
}
}
}

// parameterized build trigger build step
List<TriggerBuilder> tbl = job.getBuildersList().getAll(
TriggerBuilder.class);
@@ -519,6 +491,24 @@ private void gatherDownstreamGenerators(BuildListener listener)
}
this.gatherDownstreamGeneratorsFromTriggerBuilder(tbl, lpa,
listener);
// parameterized build trigger build trigger
BuildTrigger bt = job.getPublishersList().get(BuildTrigger.class);
this.gatherDownstreamGeneratorsFromBuildTrigger(
bt, lpa, processedProjects, listener);
// parameterized build trigger dug into a flexible publisher
FlexiblePublisher fb = job.getPublishersList().get(
FlexiblePublisher.class);
if (fb != null) {
for (ListIterator<ConditionalPublisher> cps =
fb.getPublishers().listIterator(); cps.hasNext();) {
ConditionalPublisher cp = cps.next();
BuildStep bs = cp.getPublisher();
if(BuildTrigger.class.isInstance(bs)){
this.gatherDownstreamGeneratorsFromBuildTrigger(
bt, lpa, processedProjects, listener);
}
}
}

// standard Jenkins dependencies
for(AbstractProject dp: job.getDownstreamProjects()){
@@ -536,6 +526,41 @@ private void gatherDownstreamGenerators(BuildListener listener)
}
}

private void gatherDownstreamGeneratorsFromBuildTrigger(
BuildTrigger bt,
List<ParametersAction> params,
List<AbstractProject> processedProjects,
BuildListener listener) throws Exception {
JobGenerator job = getJobGenerator();
if (bt != null) {
for (ListIterator<BuildTriggerConfig> btc =
bt.getConfigs().listIterator(); btc.hasNext();) {
BuildTriggerConfig c = btc.next();
for (AbstractProject p : c.getProjectList(job.getParent(),
null)) {
List<List<ParametersAction>> importParams =
new ArrayList<List<ParametersAction>>();
importParams.add(new ArrayList<ParametersAction>());
importParams.get(0).addAll(params);
List<AbstractBuildParameters> lbp = c.getConfigs();
for(AbstractBuildParameters bp: lbp){
if(bp.getClass().getSimpleName().equals(
"PredefinedGeneratorParameters")){
importParams.get(0).add((ParametersAction)
bp.getAction(GeneratorRun.this, listener));
}
}
if (JobGenerator.class.isInstance(p)){
job.copyOptions((JobGenerator) p);
downstreamGenerators.add(
new DownstreamGenerator(p, importParams));
processedProjects.add(p);
}
}
}
}
}

private void gatherDownstreamGeneratorsFromTriggerBuilder(
List<TriggerBuilder> builders,
List<ParametersAction> params,

0 comments on commit a492fad

Please sign in to comment.