New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PARTIALLY FIXED JENKINS-28632] Integration with Workflow to trigger a Workflow job #3
Changes from 1 commit
73d5208
d3ccd3e
50a24ae
20f8fed
2a7d028
2f6d76d
98ece8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package org.jenkinsci.plugins.deployment; | ||
|
||
import hudson.Extension; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.AutoCompletionCandidates; | ||
import hudson.model.BuildableItem; | ||
import hudson.model.Fingerprint; | ||
|
@@ -15,6 +14,7 @@ | |
import hudson.triggers.TriggerDescriptor; | ||
import jenkins.model.FingerprintFacet; | ||
import jenkins.model.Jenkins; | ||
import jenkins.model.ParameterizedJobMixIn; | ||
import org.kohsuke.stapler.AncestorInPath; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.QueryParameter; | ||
|
@@ -34,7 +34,7 @@ | |
* | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
public class DeploymentTrigger extends Trigger<AbstractProject> { | ||
public class DeploymentTrigger extends Trigger<Job> { | ||
private final String upstreamJob; | ||
private final Condition cond; | ||
|
||
|
@@ -59,6 +59,12 @@ public void checkAndFire(DeploymentFacet facet) { | |
if (upstream==null) | ||
upstream = Jenkins.getInstance().getItem(upstreamJob, job, Job.class); | ||
|
||
ParameterizedJobMixIn parameterizedJobMixIn = new ParameterizedJobMixIn() { | ||
@Override protected Job asJob() { | ||
return job; | ||
} | ||
}; | ||
|
||
RangeSet r = cond.calcMatchingBuildNumberOf(upstream, facet); | ||
if (!r.isEmpty()) { | ||
if (findTriggeredRecord(facet.getFingerprint()).add(this)) { | ||
|
@@ -67,13 +73,13 @@ public void checkAndFire(DeploymentFacet facet) { | |
if (b!=null) { | ||
// pass all the current parameters if we can | ||
ParametersAction action = b.getAction(ParametersAction.class); | ||
job.scheduleBuild(job.getQuietPeriod(), new UpstreamDeploymentCause(b), action); | ||
parameterizedJobMixIn.scheduleBuild2(5, action); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐜 Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amuniz That is incorrect as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you are still loosing some information here, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but http://javadoc.jenkins-ci.org/jenkins/model/ParameterizedJobMixIn.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you try to wrap the cause in a |
||
return; | ||
} | ||
} | ||
|
||
// didn't find any matching build, so just trigger it but without the cause to link to the upstream | ||
job.scheduleBuild(); // TODO: expose a version that takes name and build number | ||
parameterizedJobMixIn.scheduleBuild(); // TODO: expose a version that takes name and build number | ||
} | ||
} | ||
} catch (IOException e) { | ||
|
@@ -101,10 +107,15 @@ public static class ListenerImpl extends DeploymentFacetListener { | |
public void onChange(final DeploymentFacet facet, HostRecord newRecord) { | ||
POOL.submit(new Runnable() { | ||
public void run() { | ||
for (AbstractProject<?,?> p : Jenkins.getInstance().getAllItems(AbstractProject.class)) { | ||
DeploymentTrigger t = p.getTrigger(DeploymentTrigger.class); | ||
if (t!=null) { | ||
t.checkAndFire(facet); | ||
for (Job<?,?> job : Jenkins.getInstance().getAllItems(Job.class)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a note to use the new idiom in 1.621: |
||
if (job instanceof ParameterizedJobMixIn.ParameterizedJob) { | ||
ParameterizedJobMixIn.ParameterizedJob pJob = (ParameterizedJobMixIn.ParameterizedJob) job; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can just call |
||
for (Trigger trigger : pJob.getTriggers().values()) { | ||
if (trigger instanceof DeploymentTrigger) { | ||
DeploymentTrigger deploymentTrigger = (DeploymentTrigger) trigger; | ||
deploymentTrigger.checkAndFire(facet); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a TODO comment for convenience method in 1.621+.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was done.