Skip to content

Commit 4718b9b

Browse files
authored
Remove code about unsupported versions of Bitbucket Data Center (#1089)
1 parent 3ee7e7f commit 4718b9b

File tree

15 files changed

+174
-252
lines changed

15 files changed

+174
-252
lines changed

docs/USER_GUIDE.adoc

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,13 @@
11
= Bitbucket Branch Source Plugin
22

3-
[IMPORTANT]
4-
=====================================================================
5-
On March 5th, 2020, link:https://confluence.atlassian.com/bitbucketserver/bitbucket-server-7-0-release-notes-990546638.html[Atlassian releases Bitbucket Server 7]
6-
which removed some undocumented features related to pull requests.
7-
8-
. With Bitbucket Server 7.x, Jenkins Pipeline jobs can no longer perform a lightweight checkout of the `Jenkinsfile` if you are using the merge strategy for builds.
9-
.. This is due to Bitbucket Server 7.x no longer storing the merge commit for PRs to `refs/pull-requests/*/merge` which was a prerequisite for lightweight checkout.
10-
.. Bitbucket Server Pipeline jobs will automatically fall back to heavyweight checkout.
11-
.. link:https://jira.atlassian.com/browse/BSERV-12284?focusedCommentId=2389584&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-2389584[Atlassian
12-
has explained their reasons for making this change] and has made it clear they will not be re-adding this behavior.
13-
. For Jenkins Pipeline jobs to function for pull requests on Bitbucket Data Center 8.x and above, you need to enable "Call Changes api" option in the plugin configuration.
14-
.. Since Bitbucket Server 7.x no longer automatically creates the required refs for pull requests. Calls to this new API are required to trigger ref creation.
15-
16-
=====================================================================
17-
183
[id=bitbucket-sect-intro]
194

20-
_Bitbucket Branch Source plugin_ allows use of Bitbucket Cloud and Data Center
21-
as a multi-branch project source in two different ways:
5+
_Bitbucket Branch Source plugin_ allows use of Bitbucket Cloud and Data Center as a multi-branch project source in two different ways:
226

237
* *Single repository source*: automatic creation of jobs for branches and pull requests in a specific repository.
248
* *Organization folders*: automatic creation of multi-branch projects for each visible repository in a specific Bitbucket Team or Project.
259

26-
IMPORTANT: This plugin officially supports versions of Bitbucket Data Center not declared in link:https://confluence.atlassian.com/support/atlassian-end-of-support-policy-201851003.html[End Of Support (EOS)].
27-
28-
[id=bitbucket-data_center]
29-
== Bitbucket Data Center compatibility
30-
31-
_Bitbucket Data Center_ is supported but does no longer support lightweight checkout for pull requests when merge strategy is used for build.
32-
33-
IMPORTANT: In order to have the pull request process working the "Call Changes api" option must be
34-
enabled in _Manage Jenkins_ » _Configure System_
10+
IMPORTANT: Since version 937.0.0 this plugin officially supports *only* versions of Bitbucket Data Center *not* declared as in link:https://confluence.atlassian.com/support/atlassian-end-of-support-policy-201851003.html[End Of Support (EOS)].
3511

3612
[id=bitbucket-scm-source]
3713
== Branches and pull requests auto-discovering
@@ -105,7 +81,7 @@ The default Bitbucket avatar is a generated SVG image, since this plugin does no
10581
[id=bitbucket-webhooks]
10682
== Webhooks registering
10783

108-
The use of https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html[Bitbucket webhooks]
84+
The use of link:https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html[Bitbucket webhooks]
10985
allows to trigger builds on branches and pull requests just when a new commit is done. Bitbucket plugin exposes a special
11086
service to listen to these webhook requests and acts accordingly by triggering a new reindex and finally
11187
triggering builds on matching branches or pull requests.
@@ -115,11 +91,11 @@ check "Manage hooks" and select a "Credential" with enough access to add webhook
11591
it can be a System scoped credential, which will restrict its usage from Pipelines.
11692
You can setup a custom Jenkins URL to be used as callback URL by the webhooks.
11793

118-
For Bitbucket Data Center only it is possible chose which webhooks implementation server side to use:
94+
For Bitbucket Data Center only, it is possible chose which webhooks implementation server side to use:
11995

12096
- Native implementation will configure the webhooks provided by default with the Server, so it will always be available.
12197

122-
- Plugin implementation (*deprecated*) relies on the configuration available via specific APIs provided by the https://marketplace.atlassian.com/apps/1215474/post-webhooks-for-bitbucket?tab=overview&hosting=datacenter[Post Webhooks for Bitbucket] plugin itself. To get it worked plugin must be already pre-installed on the server instance. This provider allows custom settings managed by the _ignore committers_ trait. _Note: This specific implementation will be moved to an individual repository as soon as https://issues.jenkins.io/browse/JENKINS-74913[JENKINS-74913] is implemented._
98+
- Plugin implementation (*deprecated*) relies on the configuration available via specific APIs provided by the link:https://marketplace.atlassian.com/apps/1215474/post-webhooks-for-bitbucket?tab=overview&hosting=datacenter[Post Webhooks for Bitbucket] plugin itself. To get it worked plugin must be already pre-installed on the server instance. This provider allows custom settings managed by the _ignore committers_ trait. _Note: This specific implementation will be moved to an individual repository as soon as link:https://issues.jenkins.io/browse/JENKINS-74913[JENKINS-74913] is implemented._
12399

124100
image::images/screenshot-14.png[]
125101

@@ -129,7 +105,7 @@ to opt out or adjust system-wide settings.
129105
image::images/screenshot-18.png[]
130106

131107
IMPORTANT: In order to have the auto-registering process working fine the Jenkins base URL must be
132-
properly configured in _Manage Jenkins_ » _System_
108+
properly configured in _Manage Jenkins_ » _System_, in alternative the URL must be provided in the endpoint configuration.
133109

134110
=== Signature verification for incoming webhooks
135111

@@ -237,7 +213,7 @@ image::images/screenshot-12.png[]
237213
[id=bitbucket-mirror-support]
238214
== Mirror support
239215

240-
A mirrored Git repository can be configured for fetching references.
216+
A mirrored Git repository can be configured for fetching references. This feature is available only on Bitbucke Data Center.
241217

242218
The mirror is not used in the following cases:
243219

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@
136136
<artifactId>scribejava-core</artifactId>
137137
<version>8.3.3</version>
138138
</dependency>
139+
<dependency>
140+
<groupId>io.jenkins</groupId>
141+
<artifactId>configuration-as-code</artifactId>
142+
<optional>true</optional>
143+
</dependency>
139144
<dependency>
140145
<groupId>org.mockito</groupId>
141146
<artifactId>mockito-core</artifactId>
@@ -169,11 +174,6 @@
169174
<artifactId>workflow-multibranch</artifactId>
170175
<scope>test</scope>
171176
</dependency>
172-
<dependency>
173-
<groupId>io.jenkins</groupId>
174-
<artifactId>configuration-as-code</artifactId>
175-
<scope>test</scope>
176-
</dependency>
177177
<dependency>
178178
<groupId>org.mock-server</groupId>
179179
<artifactId>mockserver-junit-jupiter</artifactId>

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketEndpointConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public XmlFile getConfigFile() {
8686
XStream2 xs = new XStream2(XStream2.getDefaultDriver());
8787
xs.alias("com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint", BitbucketCloudEndpoint.class);
8888
xs.alias("com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketServerEndpoint", BitbucketServerEndpoint.class);
89+
xs.omitField(BitbucketServerEndpoint.class, "callCanMerge");
90+
xs.omitField(BitbucketServerEndpoint.class, "callChanges");
8991
return new XmlFile(xs, cfgFile);
9092
}
9193

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/HookEventType.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,12 @@ public enum HookEventType {
9898
*/
9999
SERVER_PULL_REQUEST_DELETED("pr:deleted", NativeServerPullRequestHookProcessor.class),
100100

101-
/**
102-
* See <a href="https://confluence.atlassian.com/bitbucketserver054/event-payload-939508609.html#Eventpayload-Approved">Eventpayload-Approved</a>
103-
*
104-
* @since Bitbucket Server 5.4
105-
*/
106-
SERVER_PULL_REQUEST_APPROVED("pr:reviewer:approved", NativeServerPullRequestHookProcessor.class),
107-
108101
/**
109102
* @see <a href="https://confluence.atlassian.com/bitbucketserver0510/event-payload-951390742.html#Eventpayload-Modified.1">Eventpayload: Pull Request - Modified</a>
110103
* @since Bitbucket Server 5.10
111104
*/
112105
SERVER_PULL_REQUEST_MODIFIED("pr:modified", NativeServerPullRequestHookProcessor.class),
113106

114-
/**
115-
* @see <a href="https://confluence.atlassian.com/bitbucketserver0510/event-payload-951390742.html#Eventpayload-ReviewersUpdated">Eventpayload: Pull Request - Reviewers Updated</a>
116-
* @since Bitbucket Server 5.10
117-
*/
118-
SERVER_PULL_REQUEST_REVIEWER_UPDATED("pr:reviewer:updated", NativeServerPullRequestHookProcessor.class),
119-
120107
/**
121108
* @see <a href="https://confluence.atlassian.com/bitbucketserver070/event-payload-996644369.html#Eventpayload-Sourcebranchupdated">Eventpayload-Sourcebranchupdated</a>
122109
* @since Bitbucket Server 7.0

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/NativeServerPullRequestHookProcessor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public void process(HookEventType hookEvent, String payload, BitbucketType insta
6767
eventType = SCMEvent.Type.REMOVED;
6868
break;
6969
case SERVER_PULL_REQUEST_MODIFIED,
70-
SERVER_PULL_REQUEST_REVIEWER_UPDATED,
7170
SERVER_PULL_REQUEST_FROM_REF_UPDATED:
7271
eventType = SCMEvent.Type.UPDATED;
7372
break;

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/WebhookConfiguration.java

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketCloudHook;
3131
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
3232
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
33+
import com.cloudbees.jenkins.plugins.bitbucket.server.BitbucketServerVersion;
3334
import com.cloudbees.jenkins.plugins.bitbucket.server.client.repository.BitbucketPluginWebhook;
3435
import com.cloudbees.jenkins.plugins.bitbucket.server.client.repository.BitbucketServerWebhook;
3536
import com.damnhandy.uri.template.UriTemplate;
@@ -67,20 +68,16 @@ public class WebhookConfiguration {
6768
));
6869

6970
/**
70-
* The list of events available in Bitbucket Server v7.x.
71+
* The list of events available in Bitbucket Data Center v8.x.
7172
*/
7273
private static final List<String> NATIVE_SERVER_EVENTS_v7 = Collections.unmodifiableList(Arrays.asList(
7374
HookEventType.SERVER_REFS_CHANGED.getKey(),
7475
HookEventType.SERVER_PULL_REQUEST_OPENED.getKey(),
7576
HookEventType.SERVER_PULL_REQUEST_MERGED.getKey(),
7677
HookEventType.SERVER_PULL_REQUEST_DECLINED.getKey(),
7778
HookEventType.SERVER_PULL_REQUEST_DELETED.getKey(),
78-
// only on v5.10 and above
7979
HookEventType.SERVER_PULL_REQUEST_MODIFIED.getKey(),
80-
HookEventType.SERVER_PULL_REQUEST_REVIEWER_UPDATED.getKey(),
81-
// only on v6.5 and above
8280
HookEventType.SERVER_MIRROR_REPO_SYNCHRONIZED.getKey(),
83-
// only on v7.x and above
8481
HookEventType.SERVER_PULL_REQUEST_FROM_REF_UPDATED.getKey()
8582
));
8683

@@ -98,21 +95,6 @@ public class WebhookConfiguration {
9895
"REPOSITORY_MIRROR_SYNCHRONIZED", // not supported by the hookprocessor
9996
"TAG_CREATED"));
10097

101-
/**
102-
* The list of events available in Bitbucket Server v6.5+.
103-
*/
104-
private static final List<String> NATIVE_SERVER_EVENTS_v6_5 = Collections.unmodifiableList(NATIVE_SERVER_EVENTS_v7.subList(0, 8));
105-
106-
/**
107-
* The list of events available in Bitbucket Server v6.x. Applies to v5.10+.
108-
*/
109-
private static final List<String> NATIVE_SERVER_EVENTS_v6 = Collections.unmodifiableList(NATIVE_SERVER_EVENTS_v7.subList(0, 7));
110-
111-
/**
112-
* The list of events available in Bitbucket Server v5.9-.
113-
*/
114-
private static final List<String> NATIVE_SERVER_EVENTS_v5 = Collections.unmodifiableList(NATIVE_SERVER_EVENTS_v7.subList(0, 5));
115-
11698
/**
11799
* The title of the webhook.
118100
*/
@@ -280,30 +262,13 @@ private static List<String> getNativeServerEvents(String serverURL) {
280262
.lookupEndpoint(serverURL, BitbucketServerEndpoint.class)
281263
.orElse(null);
282264
if (endpoint != null) {
283-
switch (endpoint.getServerVersion()) {
284-
case VERSION_5:
285-
return NATIVE_SERVER_EVENTS_v5;
286-
case VERSION_5_10:
287-
return NATIVE_SERVER_EVENTS_v6;
288-
case VERSION_6:
289-
// plugin version 2.9.1 introduced VERSION_6 setting for Bitbucket but it
290-
// actually applies
291-
// to Version 5.10+. In order to preserve backwards compatibility, rather than
292-
// remove
293-
// VERSION_6, it will use the same list as 5.10 until such time a need arises
294-
// for it to have its
295-
// own list
296-
return NATIVE_SERVER_EVENTS_v6;
297-
case VERSION_6_5:
298-
return NATIVE_SERVER_EVENTS_v6_5;
265+
BitbucketServerVersion serverVersion = BitbucketServerVersion.valueOf(endpoint.getServerVersion());
266+
switch (serverVersion) {
299267
case VERSION_7:
300268
default:
301269
return NATIVE_SERVER_EVENTS_v7;
302270
}
303271
}
304-
305-
// Not specifically v6, use v7.
306-
// Better to give an error than quietly not register some events.
307272
return NATIVE_SERVER_EVENTS_v7;
308273
}
309274

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2025, Nikolas Falco
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package com.cloudbees.jenkins.plugins.bitbucket.impl.casc;
25+
26+
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
27+
import com.cloudbees.jenkins.plugins.bitbucket.server.BitbucketServerWebhookImplementation;
28+
import hudson.Extension;
29+
import io.jenkins.plugins.casc.BaseConfigurator;
30+
import io.jenkins.plugins.casc.ConfigurationAsCode;
31+
import io.jenkins.plugins.casc.ConfigurationContext;
32+
import io.jenkins.plugins.casc.ConfiguratorException;
33+
import io.jenkins.plugins.casc.model.Mapping;
34+
import org.kohsuke.accmod.Restricted;
35+
import org.kohsuke.accmod.restrictions.NoExternalUse;
36+
import org.slf4j.Logger;
37+
import org.slf4j.LoggerFactory;
38+
39+
import static org.apache.commons.lang3.StringUtils.trimToNull;
40+
41+
/**
42+
* Specialised class to configure how to build a new instance of
43+
* BitbucketServerEndpoint using {@link ConfigurationAsCode}.
44+
*
45+
* @since 937.0.0
46+
*/
47+
@Extension
48+
@Restricted(NoExternalUse.class)
49+
public class BitbucketServerEndpointConfigurator extends BaseConfigurator<BitbucketServerEndpoint> {
50+
private final static Logger logger = LoggerFactory.getLogger(BitbucketServerEndpointConfigurator.class);
51+
52+
@Override
53+
public Class<BitbucketServerEndpoint> getTarget() {
54+
return BitbucketServerEndpoint.class;
55+
}
56+
57+
@Override
58+
protected BitbucketServerEndpoint instance(Mapping mapping, ConfigurationContext context) throws ConfiguratorException {
59+
final String displayName = mapping.getScalarValue("displayName");
60+
final String serverURL;
61+
if (mapping.containsKey("serverUrl")) {
62+
serverURL = mapping.getScalarValue("serverUrl");
63+
} else {
64+
serverURL = mapping.getScalarValue("serverURL");
65+
}
66+
boolean manageHooks = false;
67+
if (mapping.containsKey("manageHooks")) {
68+
manageHooks = Boolean.parseBoolean(trimToNull(mapping.getScalarValue("manageHooks")));
69+
}
70+
String credentialsId = null;
71+
if (mapping.containsKey("credentialsId")) {
72+
credentialsId = mapping.getScalarValue("credentialsId");
73+
}
74+
boolean enableHookSignature = false;
75+
if (mapping.containsKey("enableHookSignature")) {
76+
enableHookSignature = Boolean.parseBoolean(trimToNull(mapping.getScalarValue("enableHookSignature")));
77+
}
78+
String hookSignatureCredentialsId = null;
79+
if (mapping.containsKey("hookSignatureCredentialsId")) {
80+
credentialsId = mapping.getScalarValue("hookSignatureCredentialsId");
81+
}
82+
String serverVersion = null;
83+
if (mapping.containsKey("serverVersion")) {
84+
serverVersion = mapping.getScalarValue("serverVersion");
85+
}
86+
BitbucketServerWebhookImplementation webhookImplementation = null;
87+
if (mapping.containsKey("webhookImplementation")) {
88+
webhookImplementation = BitbucketServerWebhookImplementation.valueOf(mapping.getScalarValue("webhookImplementation"));
89+
}
90+
BitbucketServerEndpoint endpoint = new BitbucketServerEndpoint(displayName, serverURL, manageHooks, credentialsId, enableHookSignature, hookSignatureCredentialsId);
91+
if (serverVersion != null) {
92+
endpoint.setServerVersion(serverVersion);
93+
}
94+
if (webhookImplementation != null) {
95+
endpoint.setWebhookImplementation(webhookImplementation);
96+
}
97+
// remove unmapped attributes
98+
if (mapping.containsKey("callCanMerge")) {
99+
logger.warn("callCanMerge is deprecated and ignore for BitbucketServerEndpoint definition, remove from your CasC definition.");
100+
mapping.remove("callCanMerge");
101+
}
102+
if (mapping.containsKey("callChanges")) {
103+
logger.warn("callChanges is deprecated and ignore for BitbucketServerEndpoint definition, remove from your CasC definition.");
104+
mapping.remove("callChanges");
105+
}
106+
return endpoint;
107+
}
108+
109+
}

0 commit comments

Comments
 (0)