diff options
author | Frode Aannevik <frode.aannevik@dsafe.no> | 2016-08-05 22:53:48 +0200 |
---|---|---|
committer | Frode Aannevik <frode.aannevik@bambora.com> | 2017-02-20 00:19:30 +0100 |
commit | 725311827f86f49edcbbee1988f281dee4c6b4f2 (patch) | |
tree | c22cd5fb7c67a5142931c6f3c0301e8617000e6b /src/main | |
parent | 5472f5a59f1c004d4a85a574b5c158af88570f30 (diff) | |
download | bbprb-725311827f86f49edcbbee1988f281dee4c6b4f2.tar.gz |
Add support for Jenkins 2 (incomplete)
Replace use of AbstractProject with Job to fix
ClassCastException thrown when using the plugin
in a pipeline job
The fix is "not" complete, it remains to find a
replacement to the call AbstractProject.isDisabled
used to decide if the build should be skipped
Previously called in BitbucketBuildTrigger.run()
fixes #94
Diffstat (limited to 'src/main')
2 files changed, 25 insertions, 13 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java index 90de6b5..373c228 100644 --- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java @@ -14,6 +14,7 @@ import hudson.triggers.Trigger; import hudson.triggers.TriggerDescriptor; import hudson.util.ListBoxModel; import jenkins.model.Jenkins; +import jenkins.model.ParameterizedJobMixIn; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; import org.kohsuke.stapler.DataBoundConstructor; @@ -33,7 +34,7 @@ import static com.cloudbees.plugins.credentials.CredentialsMatchers.instanceOf; /** * Created by nishio */ -public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> { +public class BitbucketBuildTrigger extends Trigger<Job<?, ?>> { private static final Logger logger = Logger.getLogger(BitbucketBuildTrigger.class.getName()); private final String projectPath; private final String cron; @@ -153,7 +154,7 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> { } @Override - public void start(AbstractProject<?, ?> project, boolean newInstance) { + public void start(Job<?, ?> project, boolean newInstance) { try { this.bitbucketPullRequestsBuilder = BitbucketPullRequestsBuilder.getBuilder(); this.bitbucketPullRequestsBuilder.setProject(project); @@ -175,6 +176,16 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> { return this.bitbucketPullRequestsBuilder; } + private ParameterizedJobMixIn retrieveScheduleJob(final Job<?, ?> job) { + // TODO 1.621+ use standard method + return new ParameterizedJobMixIn() { + @Override + protected Job asJob() { + return job; + } + }; + } + public QueueTaskFuture<?> startJob(BitbucketCause cause) { Map<String, ParameterValue> values = this.getDefaultParameters(); @@ -183,7 +194,10 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> { abortRunningJobsThatMatch(cause); } - return this.job.scheduleBuild2(0, cause, new ParametersAction(new ArrayList(values.values())), new RevisionParameterAction(cause.getSourceCommitHash())); + return retrieveScheduleJob(this.job).scheduleBuild2(0, + new CauseAction(cause), + new ParametersAction(new ArrayList(values.values())), + new RevisionParameterAction(cause.getSourceCommitHash())); } private void cancelPreviousJobsInQueueThatMatch(@Nonnull BitbucketCause bitbucketCause) { @@ -239,11 +253,8 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> { @Override public void run() { - if(this.getBuilder().getProject().isDisabled()) { - logger.info("Build Skip."); - } else { - this.bitbucketPullRequestsBuilder.run(); - } + logger.log(Level.INFO, "TODO: check if project is disabled before calling bitbucketPullRequestsBuilder.run()"); + this.bitbucketPullRequestsBuilder.run(); this.getDescriptor().save(); } @@ -259,7 +270,7 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> { @Override public boolean isApplicable(Item item) { - return true; + return item instanceof Job && item instanceof ParameterizedJobMixIn.ParameterizedJob; } @Override diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java index 899edba..42fe562 100644 --- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketPullRequestsBuilder.java @@ -1,7 +1,6 @@ package bitbucketpullrequestbuilder.bitbucketpullrequestbuilder; import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket.Pullrequest; -import hudson.model.AbstractProject; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; @@ -11,6 +10,7 @@ import java.util.Collection; import java.util.logging.Level; import java.util.logging.Logger; +import hudson.model.Job; import org.apache.commons.codec.binary.Hex; /** @@ -18,7 +18,7 @@ import org.apache.commons.codec.binary.Hex; */ public class BitbucketPullRequestsBuilder { private static final Logger logger = Logger.getLogger(BitbucketBuildTrigger.class.getName()); - private AbstractProject<?, ?> project; + private Job<?, ?> project; private BitbucketBuildTrigger trigger; private BitbucketRepository repository; private BitbucketBuilds builds; @@ -47,7 +47,7 @@ public class BitbucketPullRequestsBuilder { return this; } - public void setProject(AbstractProject<?, ?> project) { + public void setProject(Job<?, ?> project) { this.project = project; } @@ -55,7 +55,7 @@ public class BitbucketPullRequestsBuilder { this.trigger = trigger; } - public AbstractProject<?, ?> getProject() { + public Job<?, ?> getProject() { return this.project; } @@ -73,6 +73,7 @@ public class BitbucketPullRequestsBuilder { logger.log(Level.WARNING, "Failed to produce hash", exc); } return this.project.getFullName(); + } public BitbucketBuildTrigger getTrigger() { |