Skip to content

Commit 03e4c20

Browse files
committed
Add documentation about build status.
Add comments why disableNotifications in BitbucketBuildStatusNotificationsTrait has been disabled. Rename disableNotificationForNotBuildJobs to sendStopNotificationForNotBuildJobs in BitbucketSCMContext to fit real meaning of what that options does. Before commit #200b56ca only for bitbucket server in case of not build result no status was communicated to Bitbucket.
1 parent 217b447 commit 03e4c20

File tree

5 files changed

+72
-26
lines changed

5 files changed

+72
-26
lines changed

docs/USER_GUIDE.adoc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,51 @@ For branches and tags, the mirror sync event is used. Thus, at cloning time, the
174174

175175
image::images/screenshot-13.png[scaledwidth=90%]
176176

177+
[id=bitbucket-build-status]
178+
== Bitbucket build status
179+
180+
When a new job build starts, the plugin send notifications to Bitbucket about the build status. An "In progress" notification is sent after complete the git checkout, another notification is sent at the end of the build, the sent value depends by the build result and the configuration given by the trait.
181+
182+
image::images/screenshot-15.png[scaledwidth=90%]
183+
184+
Follow a summary of all possible values:
185+
186+
[cols=3*,options=header]
187+
|===
188+
| Jenkins
189+
| Bitbucket Cloud
190+
| Bitbucket Data Center and Server
191+
192+
| https://javadoc.jenkins.io/hudson/model/Result.html#SUCCESS[SUCCESS]
193+
| SUCCESSFUL
194+
| SUCCESSFUL
195+
196+
| https://javadoc.jenkins.io/hudson/model/Result.html#UNSTABLE[UNSTABLE]
197+
| configurable SUCCESSFUL or FAILED
198+
| configurable SUCCESSFUL or FAILED
199+
200+
| https://javadoc.jenkins.io/hudson/model/Result.html#FAILURE[FAILURE]
201+
| FAILED
202+
| FAILED
203+
204+
| https://javadoc.jenkins.io/hudson/model/Result.html#NOT_BUILT[NOT_BUILT]
205+
| configurable FAILED or STOPPED
206+
| configurable FAILED or CANCELLED
207+
208+
| https://javadoc.jenkins.io/hudson/model/Result.html#ABORTED[ABORTED]
209+
| configurable FAILED or STOPPED
210+
| configurable FAILED or CANCELLED
211+
212+
| null
213+
| INPROGRESS
214+
| INPROGRESS
215+
|===
216+
217+
The STOPPED status prevents merge checks on Cloud, CANCELLED status should prevents merge checks on Data Center
218+
219+
If this does not meet you need you can disable any notification to Bitbucket using the https://github.com/jenkinsci/skip-notifications-trait-plugin/[skip-notifications-trait-plugin] and provide notification about the build status yourself. This can be achieved via a curl shell command or by using build steps provided by the https://github.com/jenkinsci/bitbucket-build-status-notifier-plugin[bitbucket-build-status-notifier-plugin].
220+
221+
177222
[id=bitbucket-misc-config]
178223
== Miscellaneous configuration
179224

docs/images/screenshot-15.png

64.1 KB
Loading

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketBuildStatusNotifications.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private static void createStatus(@NonNull Run<?, ?> build,
145145
state = BitbucketBuildStatus.Status.FAILED;
146146
} else if (Result.NOT_BUILT.equals(result)) {
147147
statusDescription = StringUtils.defaultIfBlank(buildDescription, "This commit was not built (probably the build was skipped)");
148-
if (context.disableNotificationForNotBuildJobs()) {
148+
if (context.sendStopNotificationForNotBuildJobs()) {
149149
// Bitbucket Cloud and Server support different build states.
150150
state = (bitbucket instanceof BitbucketCloudApiClient) ? BitbucketBuildStatus.Status.STOPPED : BitbucketBuildStatus.Status.CANCELLED;
151151
} else {
@@ -185,6 +185,7 @@ private static void sendNotifications(BitbucketSCMSource source, Run<?, ?> build
185185
BitbucketSCMSourceContext sourceContext = new BitbucketSCMSourceContext(null,
186186
SCMHeadObserver.none()).withTraits(source.getTraits());
187187
if (sourceContext.notificationsDisabled()) {
188+
listener.getLogger().println("[Bitbucket] Notification is disabled by configuration");
188189
return;
189190
}
190191
SCMRevision rev = SCMRevisionAction.getRevision(source, build);

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketBuildStatusNotificationsTrait.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package com.cloudbees.jenkins.plugins.bitbucket;
2525

26+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2627
import hudson.Extension;
2728
import jenkins.scm.api.SCMSource;
2829
import jenkins.scm.api.trait.SCMSourceContext;
@@ -40,20 +41,12 @@
4041
*/
4142
public class BitbucketBuildStatusNotificationsTrait extends SCMSourceTrait {
4243

43-
/**
44-
* Should unstable builds be communicated as success to Bitbucket.
45-
*/
4644
private boolean sendSuccessNotificationForUnstableBuild;
47-
48-
/**
49-
* Aborted jobs must be communicated as stopped to Bitbucket.
50-
*/
5145
private boolean sendStoppedNotificationForAbortBuild;
52-
53-
/**
54-
* Should not build jobs be communicated to Bitbucket.
55-
*/
5646
private boolean disableNotificationForNotBuildJobs;
47+
// seems that this attribute as been moved out to plugin skip-notifications-trait-plugin
48+
@SuppressFBWarnings("UUF_UNUSED_FIELD")
49+
private transient boolean disableNotifications;
5750

5851
/**
5952
* Constructor.
@@ -72,6 +65,8 @@ public void setSendSuccessNotificationForUnstableBuild(boolean isSendSuccess) {
7265
}
7366

7467
/**
68+
* Should unstable builds be communicated as success to Bitbucket.
69+
*
7570
* @return if unstable builds will be communicated as successful
7671
*/
7772
public boolean getSendSuccessNotificationForUnstableBuild() {
@@ -92,7 +87,7 @@ public void setSendStoppedNotificationForAbortBuild(boolean sendStop) {
9287
/**
9388
* Return if aborted builds will be communicated as stopped.
9489
*
95-
* @return true will be comunicate to Bitbucket as Stopped/Cancelled build
90+
* @return if will be communicated to Bitbucket as Stopped/Cancelled build
9691
* failed otherwise.
9792
*/
9893
public boolean getSendStoppedNotificationForAbortBuild() {
@@ -105,7 +100,10 @@ public void setDisableNotificationForNotBuildJobs(boolean isNotificationDisabled
105100
}
106101

107102
/**
108-
* @return if unstable builds will be communicated
103+
* Should not build jobs be communicated as stopped.
104+
*
105+
* @return if will be communicated to Bitbucket as Stopped/Cancelled build
106+
* failed otherwise.
109107
*/
110108
public boolean getDisableNotificationForNotBuildJobs() {
111109
return this.disableNotificationForNotBuildJobs;
@@ -116,9 +114,11 @@ public boolean getDisableNotificationForNotBuildJobs() {
116114
*/
117115
@Override
118116
protected void decorateContext(SCMSourceContext<?, ?> context) {
119-
((BitbucketSCMSourceContext) context).withDisableNotificationForNotBuildJobs(getDisableNotificationForNotBuildJobs());
120-
((BitbucketSCMSourceContext) context).withSendSuccessNotificationForUnstableBuild(getSendSuccessNotificationForUnstableBuild());
121-
((BitbucketSCMSourceContext) context).withSendStoppedNotificationForAbortBuild(getSendStoppedNotificationForAbortBuild());
117+
if (context instanceof BitbucketSCMSourceContext scmContext) {
118+
scmContext.withSendStopNotificationForNotBuildJobs(getDisableNotificationForNotBuildJobs());
119+
scmContext.withSendSuccessNotificationForUnstableBuild(getSendSuccessNotificationForUnstableBuild());
120+
scmContext.withSendStoppedNotificationForAbortBuild(getSendStoppedNotificationForAbortBuild());
121+
}
122122
}
123123

124124
/**

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSourceContext.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public class BitbucketSCMSourceContext extends SCMSourceContext<BitbucketSCMSour
9898
private boolean sendStoppedNotificationForAbortBuild;
9999

100100
/**
101-
* {@code false} if not built jobs should be send to Bitbucket.
101+
* {@code false} if not built jobs will be communicated as stopped/cancelled.
102102
*/
103-
private boolean disableNotificationForNotBuildJobs;
103+
private boolean sendStopNotificationForNotBuildJobs;
104104

105105
/**
106106
* Constructor.
@@ -235,12 +235,12 @@ public final boolean sendSuccessNotificationForUnstableBuild() {
235235
}
236236

237237
/**
238-
* Returns {@code false} if not build jobs should be passed to Bitbucket.
238+
* Returns if not build jobs should be passed as stopped/cancelled to Bitbucket.
239239
*
240-
* @return {@code false} if not build jobs should be passed to Bitbucket.
240+
* @return if not build jobs should be passed as stopped to Bitbucket.
241241
*/
242-
public boolean disableNotificationForNotBuildJobs() {
243-
return disableNotificationForNotBuildJobs;
242+
public boolean sendStopNotificationForNotBuildJobs() {
243+
return sendStopNotificationForNotBuildJobs;
244244
}
245245

246246
/**
@@ -395,12 +395,12 @@ public final BitbucketSCMSourceContext withSendStoppedNotificationForAbortBuild(
395395
/**
396396
* Defines behaviour of not-built jobs in Bitbucket.
397397
*
398-
* @param disabled {@code false} to report not-built jobs to Bitbucket.
398+
* @param sendStopped {@code false} to consider aborted builds as stopped when notifying Bitbucket.
399399
* @return {@code this} for method chaining.
400400
*/
401401
@NonNull
402-
public final BitbucketSCMSourceContext withDisableNotificationForNotBuildJobs(boolean disabled) {
403-
this.disableNotificationForNotBuildJobs = disabled;
402+
public final BitbucketSCMSourceContext withSendStopNotificationForNotBuildJobs(boolean sendStopped) {
403+
this.sendStopNotificationForNotBuildJobs = sendStopped;
404404
return this;
405405
}
406406

0 commit comments

Comments
 (0)