Skip to content
Permalink
Browse files
Merge pull request #19 from fbelzunc/JENKINS-29096
[FIXED JENKINS-29096] Advice users when they don't use the right hook url
  • Loading branch information
fbelzunc committed Oct 10, 2015
2 parents 2f45c5f + 81473e8 commit e20b8b3360910d4a4b3ca9e9c560cfd218c3f9d9
Showing with 16 additions and 9 deletions.
  1. +16 −9 src/main/java/com/cloudbees/jenkins/plugins/BitbucketHookReceiver.java
@@ -5,6 +5,7 @@

import java.io.IOException;
import java.net.URLDecoder;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.sf.json.JSONObject;
@@ -19,6 +20,7 @@
public class BitbucketHookReceiver implements UnprotectedRootAction {

private final BitbucketPayloadProcessor payloadProcessor = new BitbucketPayloadProcessor();
private final String BITBUCKET_HOOK_URL = "bitbucket-hook";

public String getIconFileName() {
return null;
@@ -29,7 +31,7 @@ public String getDisplayName() {
}

public String getUrlName() {
return "bitbucket-hook";
return BITBUCKET_HOOK_URL;
}

/**
@@ -39,16 +41,21 @@ public String getUrlName() {
*/
public void doIndex(StaplerRequest req) throws IOException {
String body = IOUtils.toString(req.getInputStream());
String contentType = req.getContentType();
if (contentType != null && contentType.startsWith("application/x-www-form-urlencoded")) {
body = URLDecoder.decode(body);
if (!body.isEmpty() && req.getRequestURI().contains("/" + BITBUCKET_HOOK_URL + "/")) {
String contentType = req.getContentType();
if (contentType != null && contentType.startsWith("application/x-www-form-urlencoded")) {
body = URLDecoder.decode(body);
}
if (body.startsWith("payload=")) body = body.substring(8);

LOGGER.log(Level.FINE, "Received commit hook notification : {0}", body);
JSONObject payload = JSONObject.fromObject(body);

payloadProcessor.processPayload(payload, req);
} else {
LOGGER.log(Level.WARNING, "The Jenkins job cannot be triggered. You might no have configured correctly the WebHook on BitBucket with the last slash `http://<JENKINS-URL>/bitbucket-hook/`");
}
if (body.startsWith("payload=")) body = body.substring(8);

LOGGER.fine("Received commit hook notification : " + body);
JSONObject payload = JSONObject.fromObject(body);

payloadProcessor.processPayload(payload, req);
}

private static final Logger LOGGER = Logger.getLogger(BitbucketHookReceiver.class.getName());

0 comments on commit e20b8b3

Please sign in to comment.