Skip to content
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

Merged
merged 7 commits into from Nov 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.509</version><!-- which version of Jenkins is this plugin built against? -->
<version>1.580.1</version><!-- minimun required version to work with Workflow -->
</parent>

<artifactId>deployment-notification</artifactId>
Expand Down Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>promoted-builds</artifactId>
<version>2.7</version>
<version>2.15</version>
<optional>true</optional>
</dependency>
</dependencies>
Expand Down
@@ -1,9 +1,9 @@
package org.jenkinsci.plugins.deployment;

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.AutoCompletionCandidates;
import hudson.model.BuildableItem;
import hudson.model.CauseAction;
import hudson.model.Fingerprint;
import hudson.model.Fingerprint.RangeSet;
import hudson.model.Item;
Expand All @@ -15,6 +15,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;
Expand All @@ -34,7 +35,7 @@
*
* @author Kohsuke Kawaguchi
*/
public class DeploymentTrigger extends Trigger<AbstractProject> {
public class DeploymentTrigger extends Trigger<Job> {
private final String upstreamJob;
private final Condition cond;

Expand All @@ -59,6 +60,13 @@ public void checkAndFire(DeploymentFacet facet) {
if (upstream==null)
upstream = Jenkins.getInstance().getItem(upstreamJob, job, Job.class);

//TODO: Jenkins 1.621+ can avoid to implement an inner inline class in code directly calling ParameterizedJobMixIn.scheduleBuild2
ParameterizedJobMixIn parameterizedJobMixIn = new ParameterizedJobMixIn() {
@Override protected Job asJob() {
return job;
}
};
Copy link
Member

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+.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done.


RangeSet r = cond.calcMatchingBuildNumberOf(upstream, facet);
if (!r.isEmpty()) {
if (findTriggeredRecord(facet.getFingerprint()).add(this)) {
Expand All @@ -67,13 +75,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, new CauseAction(new UpstreamDeploymentCause(b)), action);
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) {
Expand Down Expand Up @@ -101,10 +109,13 @@ 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);
//TODO - 1.621: use getTrigger(Job<?,?> job, Class<T> clazz)
for (ParameterizedJobMixIn.ParameterizedJob parameterizedJob : Jenkins.getInstance().getAllItems(ParameterizedJobMixIn.ParameterizedJob.class)) {
for (Trigger trigger : parameterizedJob.getTriggers().values()) {
if (trigger instanceof DeploymentTrigger) {
DeploymentTrigger deploymentTrigger = (DeploymentTrigger) trigger;
deploymentTrigger.checkAndFire(facet);
}
}
}
}
Expand Down