diff options
author | Frode Aannevik <frode.aa@gmail.com> | 2017-02-12 17:05:15 +0100 |
---|---|---|
committer | Frode Aannevik <frode.aannevik@bambora.com> | 2017-02-20 00:19:30 +0100 |
commit | 0debdfbdf1846f74928e0c4e932475b77e655a06 (patch) | |
tree | 0dffac3389f7571da134c4dc64bca749eae35bfb /src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuilds.java | |
parent | 066fc6386f08729ac2861e29b4bba91427541724 (diff) | |
download | bbprb-0debdfbdf1846f74928e0c4e932475b77e655a06.tar.gz |
Fix PR build status and update of job description
BitbucketBuildListener was not invoked on
pipeline jobs
Change BitbucketBuildListener to extend from
RunListener<Run<?, ?>> so it will invoked to
update job description and PR build result
Diffstat (limited to 'src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuilds.java')
-rw-r--r-- | src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuilds.java | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuilds.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuilds.java index ea8e892..216287d 100644 --- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuilds.java +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuilds.java @@ -1,10 +1,7 @@ package bitbucketpullrequestbuilder.bitbucketpullrequestbuilder; import bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket.BuildState; -import hudson.model.AbstractBuild; -import hudson.model.Cause; -import hudson.model.Result; -import jenkins.model.Jenkins; +import hudson.model.*; import jenkins.model.JenkinsLocationConfiguration; import java.io.IOException; @@ -24,16 +21,7 @@ public class BitbucketBuilds { this.repository = repository; } - public BitbucketCause getCause(AbstractBuild build) { - Cause cause = build.getCause(BitbucketCause.class); - if (cause == null || !(cause instanceof BitbucketCause)) { - return null; - } - return (BitbucketCause) cause; - } - - public void onStarted(AbstractBuild build) { - BitbucketCause cause = this.getCause(build); + void onStarted(BitbucketCause cause, Run<?, ?> build) { if (cause == null) { return; } @@ -44,24 +32,21 @@ public class BitbucketBuilds { } } - public void onCompleted(AbstractBuild build) { - BitbucketCause cause = this.getCause(build); + void onCompleted(BitbucketCause cause, Result result, String buildUrl) { if (cause == null) { return; } - Result result = build.getResult(); JenkinsLocationConfiguration globalConfig = new JenkinsLocationConfiguration(); String rootUrl = globalConfig.getUrl(); - String buildUrl = ""; if (rootUrl == null) { logger.warning("PLEASE SET JENKINS ROOT URL IN GLOBAL CONFIGURATION FOR BUILD STATE REPORTING"); } else { - buildUrl = rootUrl + build.getUrl(); + buildUrl = rootUrl + buildUrl; BuildState state = result == Result.SUCCESS ? BuildState.SUCCESSFUL : BuildState.FAILED; repository.setBuildStatus(cause, state, buildUrl); } - if ( this.trigger.getApproveIfSuccess() && result == Result.SUCCESS ) { + if (this.trigger.getApproveIfSuccess() && result == Result.SUCCESS) { this.repository.postPullRequestApproval(cause.getPullRequestId()); } } |