Skip to content

Commit 5f2a524

Browse files
committed
[JENKINS-74913] Allow extension point in bitbucket source plugin to provide a implementation for web-hooks management
Add webhook extensible interface to provide custom implementation of wehbook from configuration to the APIs to register it on Bitbucket
1 parent 8dc3d83 commit 5f2a524

File tree

101 files changed

+203
-1294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+203
-1294
lines changed

docs/USER_GUIDE.adoc

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ If you want be able to perform git push operation from CLI than you have to setu
192192

193193
image::images/screenshot-17.png[]
194194

195-
=== App Passwords - DEPRECATED (Bitbucket Cloud only)
195+
=== App Passwords (Bitbucket Cloud only)
196196

197197
Bitbucket https://community.atlassian.com/t5/Bitbucket-articles/Announcement-Bitbucket-Cloud-account-password-usage-for-Git-over/ba-p/1948231[deprecated usage of Atlassian account password] for Bitbucket API and Git over HTTPS starting from March 1st, 2022.
198198

@@ -203,21 +203,6 @@ First, create a new _app password_ in Bitbucket as instructed in the https://sup
203203
Then create a new _Username with password credentials_ in Jenkins, enter the Bitbucket username (not the email) in the _Username_ field and the created app password in the _Password_ field.
204204

205205
IMPORTANT: App passwords do not support email address as a username for authentication. Using the email address will raise an authentication error in scanning/checkout process.
206-
The app passoword authentication has been deprecated by Atlassian and starting from September 9th, 2025 will not longer available for creation. https://www.atlassian.com/blog/bitbucket/bitbucket-cloud-transitions-to-api-tokens-enhancing-security-with-app-password-deprecation[Read here] for more informations.
207-
208-
=== User API Token (Bitbucket Cloud only)
209-
210-
Bitbucket https://www.atlassian.com/blog/bitbucket/bitbucket-cloud-transitions-to-api-tokens-enhancing-security-with-app-password-deprecation[deprecated usage of Atlassian App Password] for Bitbucket API and Git over HTTPS starting from September 9th, 2025.
211-
212-
The plugin can make use of an user API token with scopes instead of the app password.
213-
214-
First, create a new _User API token_ in Bitbucket as instructed in the https://support.atlassian.com/bitbucket-cloud/docs/create-an-api-token/[Bitbucket API Token Documentation]. At least allow _read_ access for project, repositories and pull requests. Also, you may need to allow _read_ and _write_ access for webhooks depending on your pipeline's triggers.
215-
216-
image::images/screenshot-22.png[]
217-
218-
Then create a new _Username with password credentials_ in Jenkins, enter the Atlassian Account email (not the username) in the _Username_ field and the created API token in the _Password_ field.
219-
220-
IMPORTANT: API token requires the email address as a username to authenticate using the BitbucketAPIs. Using the username will raise an authentication error in scanning/checkout process. API token without scope does not work.
221206

222207
=== OAuth credentials (Bitbucket Cloud only)
223208

docs/images/screenshot-22.png

-30.5 KB
Binary file not shown.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
* THE SOFTWARE.
2323
*/
24-
package com.cloudbees.jenkins.plugins.bitbucket.api.webhook;
24+
package com.cloudbees.jenkins.plugins.bitbucket.api.hook;
2525

2626
import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource;
2727
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpoint;
@@ -47,7 +47,7 @@
4747
* the incoming request as much as possible or the hook will be rejected.
4848
*/
4949
@Restricted(Beta.class)
50-
public interface BitbucketWebhookProcessor extends ExtensionPoint {
50+
public interface BitbucketHookProcessor extends ExtensionPoint {
5151
static final String SCAN_ON_EMPTY_CHANGES_PROPERTY_NAME = "bitbucket.hooks.processor.scanOnEmptyChanges";
5252

5353
/**
@@ -104,11 +104,11 @@ default Map<String, Object> buildHookContext(@NonNull HttpServletRequest request
104104
* @param payload request
105105
* @param endpoint configured for the given
106106
* {@link #getServerURL(Map, MultiValuedMap)}
107-
* @throws BitbucketWebhookProcessorException when signature verification fails
107+
* @throws BitbucketHookProcessorException when signature verification fails
108108
*/
109109
void verifyPayload(@NonNull Map<String, String> headers,
110110
@NonNull String payload,
111-
@NonNull BitbucketEndpoint endpoint) throws BitbucketWebhookProcessorException;
111+
@NonNull BitbucketEndpoint endpoint) throws BitbucketHookProcessorException;
112112

113113
/**
114114
* Settings that will trigger a re-index of the multibranch
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
* THE SOFTWARE.
2323
*/
24-
package com.cloudbees.jenkins.plugins.bitbucket.api.webhook;
24+
package com.cloudbees.jenkins.plugins.bitbucket.api.hook;
2525

2626
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketException;
2727

28-
public class BitbucketWebhookProcessorException extends BitbucketException {
28+
public class BitbucketHookProcessorException extends BitbucketException {
2929
private static final long serialVersionUID = 6682700868741672883L;
3030
private final int httpCode;
3131

32-
public BitbucketWebhookProcessorException(int httpCode, String message) {
32+
public BitbucketHookProcessorException(int httpCode, String message) {
3333
super(message);
3434
this.httpCode = httpCode;
3535
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/webhook/BitbucketWebhook.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/webhook/BitbucketWebhookDescriptor.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.cloudbees.jenkins.plugins.bitbucket.impl.client.ICheckedCallable;
4848
import com.cloudbees.jenkins.plugins.bitbucket.impl.credentials.BitbucketAccessTokenAuthenticator;
4949
import com.cloudbees.jenkins.plugins.bitbucket.impl.credentials.BitbucketOAuthAuthenticator;
50-
import com.cloudbees.jenkins.plugins.bitbucket.impl.credentials.BitbucketUserAPITokenAuthenticator;
5150
import com.cloudbees.jenkins.plugins.bitbucket.impl.credentials.BitbucketUsernamePasswordAuthenticator;
5251
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
5352
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.JsonParser;
@@ -148,7 +147,6 @@ protected boolean isSupportedAuthenticator(@CheckForNull BitbucketAuthenticator
148147
return authenticator == null
149148
|| authenticator instanceof BitbucketAccessTokenAuthenticator
150149
|| authenticator instanceof BitbucketOAuthAuthenticator
151-
|| authenticator instanceof BitbucketUserAPITokenAuthenticator // API access token
152150
|| authenticator instanceof BitbucketUsernamePasswordAuthenticator; // app password
153151
}
154152

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpoint;
2727
import com.cloudbees.jenkins.plugins.bitbucket.api.endpoint.BitbucketEndpointProvider;
28-
import com.cloudbees.jenkins.plugins.bitbucket.api.webhook.BitbucketWebhookProcessor;
29-
import com.cloudbees.jenkins.plugins.bitbucket.api.webhook.BitbucketWebhookProcessorException;
28+
import com.cloudbees.jenkins.plugins.bitbucket.api.hook.BitbucketHookProcessor;
29+
import com.cloudbees.jenkins.plugins.bitbucket.api.hook.BitbucketHookProcessorException;
3030
import hudson.Extension;
3131
import hudson.ExtensionList;
3232
import hudson.model.UnprotectedRootAction;
@@ -93,7 +93,7 @@ public HttpResponse doNotify(StaplerRequest2 req) throws IOException {
9393
try {
9494
Map<String, String> reqHeaders = getHeaders(req);
9595
MultiValuedMap<String, String> reqParameters = getParameters(req);
96-
BitbucketWebhookProcessor hookProcessor = getHookProcessor(reqHeaders, reqParameters);
96+
BitbucketHookProcessor hookProcessor = getHookProcessor(reqHeaders, reqParameters);
9797

9898
String body = IOUtils.toString(req.getInputStream(), StandardCharsets.UTF_8);
9999
if (StringUtils.isEmpty(body)) {
@@ -120,37 +120,37 @@ public HttpResponse doNotify(StaplerRequest2 req) throws IOException {
120120
String eventType = hookProcessor.getEventType(Collections.unmodifiableMap(reqHeaders), MultiMapUtils.unmodifiableMultiValuedMap(reqParameters));
121121

122122
hookProcessor.process(eventType, body, context, endpoint);
123-
} catch(BitbucketWebhookProcessorException e) {
123+
} catch(BitbucketHookProcessorException e) {
124124
return HttpResponses.error(e.getHttpCode(), e.getMessage());
125125
}
126126
return HttpResponses.ok();
127127
}
128128

129-
private BitbucketWebhookProcessor getHookProcessor(Map<String, String> reqHeaders,
129+
private BitbucketHookProcessor getHookProcessor(Map<String, String> reqHeaders,
130130
MultiValuedMap<String, String> reqParameters) {
131-
BitbucketWebhookProcessor hookProcessor;
131+
BitbucketHookProcessor hookProcessor;
132132

133-
List<BitbucketWebhookProcessor> matchingProcessors = getHookProcessors()
133+
List<BitbucketHookProcessor> matchingProcessors = getHookProcessors()
134134
.filter(processor -> processor.canHandle(Collections.unmodifiableMap(reqHeaders), MultiMapUtils.unmodifiableMultiValuedMap(reqParameters)))
135135
.toList();
136136
if (matchingProcessors.isEmpty()) {
137137
logger.warning(() -> "No processor found for the incoming Bitbucket hook. Skipping.");
138-
throw new BitbucketWebhookProcessorException(HttpServletResponse.SC_BAD_REQUEST, "No processor found that supports this event. Refer to the user documentation on how configure the webHook in Bitbucket at https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/master/docs/USER_GUIDE.adoc#webhooks-registering");
138+
throw new BitbucketHookProcessorException(HttpServletResponse.SC_BAD_REQUEST, "No processor found that supports this event. Refer to the user documentation on how configure the webHook in Bitbucket at https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/master/docs/USER_GUIDE.adoc#webhooks-registering");
139139
} else if (matchingProcessors.size() > 1) {
140140
String processors = StringUtils.joinWith("\n- ", matchingProcessors.stream()
141141
.map(p -> p.getClass().getName())
142142
.toList());
143143
logger.severe(() -> "More processors found that handle the incoming Bitbucket hook:\n" + processors);
144-
throw new BitbucketWebhookProcessorException(HttpServletResponse.SC_CONFLICT, "More processors found that handle the incoming Bitbucket hook.");
144+
throw new BitbucketHookProcessorException(HttpServletResponse.SC_CONFLICT, "More processors found that handle the incoming Bitbucket hook.");
145145
} else {
146146
hookProcessor = matchingProcessors.get(0);
147147
logger.fine(() -> "Hook processor " + hookProcessor.getClass().getName() + " found.");
148148
}
149149
return hookProcessor;
150150
}
151151

152-
/*test*/ Stream<BitbucketWebhookProcessor> getHookProcessors() {
153-
return ExtensionList.lookup(BitbucketWebhookProcessor.class).stream();
152+
/*test*/ Stream<BitbucketHookProcessor> getHookProcessors() {
153+
return ExtensionList.lookup(BitbucketHookProcessor.class).stream();
154154
}
155155

156156
private MultiValuedMap<String, String> getParameters(StaplerRequest2 req) {

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/credentials/BitbucketUserAPITokenAuthenticator.java

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/credentials/BitbucketUserAPITokenAuthenticatorSource.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)