From 6e80330f3fda22104adae07ff3fb6f6dc3fb8b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Belzunce=20Arcos?= Date: Thu, 2 Nov 2017 11:07:52 +0100 Subject: [PATCH 01/12] [JENKINS-47782] Add findbugs-exclude.xml --- findbugs-exclude.xml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 findbugs-exclude.xml diff --git a/findbugs-exclude.xml b/findbugs-exclude.xml new file mode 100644 index 00000000..f4dbf542 --- /dev/null +++ b/findbugs-exclude.xml @@ -0,0 +1,5 @@ + + + + + From 0653a6508cea802f498d296cf9d47a82eb3e7916 Mon Sep 17 00:00:00 2001 From: Felix Belzunce Arcos Date: Thu, 2 Nov 2017 11:27:49 +0100 Subject: [PATCH 02/12] [JENKINS-47782] Skip findbugs --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 53ff98b1..76161880 100644 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,7 @@ org.codehaus.mojo findbugs-maven-plugin + true findbugs-exclude.xml @@ -150,4 +151,4 @@ - \ No newline at end of file + From 9c1768c053ace7eba7c27e4d65f968ec8a675c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Belzunce=20Arcos?= Date: Thu, 2 Nov 2017 11:30:09 +0100 Subject: [PATCH 03/12] [maven-release-plugin] prepare release bitbucket-1.1.6 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 76161880..4c3c93b3 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ bitbucket - 1.1.6-SNAPSHOT + 1.1.6 hpi Jenkins Bitbucket Plugin integrate Jenkins with BitBucket. @@ -18,7 +18,7 @@ scm:git:git://github.com/jenkinsci/bitbucket-plugin.git scm:git:git@github.com:jenkinsci/bitbucket-plugin.git https://github.com/jenkinsci/bitbucket-plugin - HEAD + bitbucket-1.1.6 From 2ed382bc5174c5034a9e68674361f04280b187ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Belzunce=20Arcos?= Date: Thu, 2 Nov 2017 11:30:20 +0100 Subject: [PATCH 04/12] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4c3c93b3..840517c2 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ bitbucket - 1.1.6 + 1.1.7-SNAPSHOT hpi Jenkins Bitbucket Plugin integrate Jenkins with BitBucket. @@ -18,7 +18,7 @@ scm:git:git://github.com/jenkinsci/bitbucket-plugin.git scm:git:git@github.com:jenkinsci/bitbucket-plugin.git https://github.com/jenkinsci/bitbucket-plugin - bitbucket-1.1.6 + HEAD From 4c5aa5f057837b672c9497162be7ca95317bddf9 Mon Sep 17 00:00:00 2001 From: "fbelzunc@gmail.com" Date: Wed, 6 Dec 2017 13:23:51 +0100 Subject: [PATCH 05/12] Add Jenkinsfile --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..48bf230e --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1 @@ +buildPlugin() \ No newline at end of file From 5701ae36d396220737a9742022d5593b9774f162 Mon Sep 17 00:00:00 2001 From: Felix Belzunce Arcos Date: Wed, 6 Dec 2017 13:55:12 +0100 Subject: [PATCH 06/12] [FIXED JENKINS-28877] Adding BitBucket server webhook (#53) [JENKINS-28877] Adding BitBucket server webhook --- .../plugins/BitbucketPayloadProcessor.java | 34 +++++++++++++++++++ .../BitbucketPayloadProcessorTest.java | 27 +++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessor.java b/src/main/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessor.java index cf9f4a36..a6b34b57 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessor.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessor.java @@ -1,5 +1,7 @@ package com.cloudbees.jenkins.plugins; +import java.net.MalformedURLException; +import java.net.URL; import java.util.logging.Level; import java.util.logging.Logger; @@ -25,6 +27,11 @@ public void processPayload(JSONObject payload, HttpServletRequest request) { LOGGER.log(Level.INFO, "Processing new Webhooks payload"); processWebhookPayload(payload); } + } else if (payload.has("actor") && payload.has("repository")) { + if ("repo:push".equals(request.getHeader("x-event-key"))) { + LOGGER.log(Level.INFO, "Processing new Webhooks payload"); + processWebhookPayloadBitBucketServer(payload); + } } else { LOGGER.log(Level.INFO, "Processing old POST service payload"); processPostServicePayload(payload); @@ -52,6 +59,33 @@ private void processWebhookPayload(JSONObject payload) { } + /** + * Payload processor for BitBucket server. The plugin Post Webhooks for Bitbucket + * https://marketplace.atlassian.com/plugins/nl.topicus.bitbucket.bitbucket-webhooks/server/overview + * should be installed and configured + * + * @param payload + */ + private void processWebhookPayloadBitBucketServer(JSONObject payload) { + JSONObject repo = payload.getJSONObject("repository"); + String user = payload.getJSONObject("actor").getString("username"); + String url = ""; + if (repo.getJSONObject("links").getJSONArray("self").size() != 0) { + try { + URL pushHref = new URL(repo.getJSONObject("links").getJSONArray("self").getJSONObject(0).getString("href")); + if (pushHref.getProtocol().equals("https")) { + url = pushHref.toString().replaceFirst(new String("projects.*"), new String("scm/" + repo.getString("fullName").toLowerCase())); + } else { + url = pushHref.toString().replaceFirst(new String("projects.*"), new String(repo.getString("fullName").toLowerCase())); + } + String scm = repo.has("scmId") ? repo.getString("scmId") : "git"; + probe.triggerMatchingJobs(user, url, scm, payload.toString()); + } catch (MalformedURLException e) { + LOGGER.log(Level.WARNING, String.format("URL %s is malformed", url), e); + } + } + } + /* { "canon_url": "https://bitbucket.org", diff --git a/src/test/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessorTest.java b/src/test/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessorTest.java index af4f4d5d..6a5c4733 100644 --- a/src/test/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessorTest.java +++ b/src/test/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessorTest.java @@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletRequest; +import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.junit.Before; @@ -60,6 +61,32 @@ public void testProcessWebhookPayload() { verify(probe).triggerMatchingJobs(user, url, "hg", hgLoad.toString()); } + @Test + public void processWebhookPayloadBitBucketServer() { + // Set headers so that payload processor will parse as new Webhook payload + when(request.getHeader("user-agent")).thenReturn("Apache-HttpClient/4.5.1 (Java/1.8.0_102)"); + when(request.getHeader("x-event-key")).thenReturn("repo:push"); + + String user = "test_user"; + String url = "https://bitbucket.org/scm/ce/test_repo"; + + JSONObject href = new JSONObject(); + href.element("href", "https://bitbucket.org/projects/CE/repos/test_repo/browse"); + + JSONObject payload = new JSONObject() + .element("actor", new JSONObject() + .element("username", user)) + .element("repository", new JSONObject() + .element("links", new JSONObject() + .element("self", new JSONArray() + .element(href))) + .element("fullName", "CE/test_repo")); + + payloadProcessor.processPayload(payload, request); + + verify(probe).triggerMatchingJobs(user, url, "git", payload.toString()); + } + @Test public void testProcessPostServicePayload() { // Ensure header isn't set so that payload processor will parse as old POST service payload From b5a4a0659a7a616555f26ce8d4a7838db2683abd Mon Sep 17 00:00:00 2001 From: "fbelzunc@gmail.com" Date: Wed, 6 Dec 2017 13:59:29 +0100 Subject: [PATCH 07/12] [maven-release-plugin] prepare release bitbucket-1.1.7 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 840517c2..78136a04 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ bitbucket - 1.1.7-SNAPSHOT + 1.1.7 hpi Jenkins Bitbucket Plugin integrate Jenkins with BitBucket. @@ -18,7 +18,7 @@ scm:git:git://github.com/jenkinsci/bitbucket-plugin.git scm:git:git@github.com:jenkinsci/bitbucket-plugin.git https://github.com/jenkinsci/bitbucket-plugin - HEAD + bitbucket-1.1.7 From 1d6566934d59a22e0e427810129de6b0aa5e9eca Mon Sep 17 00:00:00 2001 From: "fbelzunc@gmail.com" Date: Wed, 6 Dec 2017 13:59:37 +0100 Subject: [PATCH 08/12] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 78136a04..e0b1d081 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ bitbucket - 1.1.7 + 1.1.8-SNAPSHOT hpi Jenkins Bitbucket Plugin integrate Jenkins with BitBucket. @@ -18,7 +18,7 @@ scm:git:git://github.com/jenkinsci/bitbucket-plugin.git scm:git:git@github.com:jenkinsci/bitbucket-plugin.git https://github.com/jenkinsci/bitbucket-plugin - bitbucket-1.1.7 + HEAD From 362bf39dcaa310940e093306acffc2df095ef30a Mon Sep 17 00:00:00 2001 From: Frieder Rick Date: Wed, 6 Dec 2017 18:30:35 +0100 Subject: [PATCH 09/12] [JENKINS-28877] remove /scm before GitStatus.looselyMatches to match ssh and https URI in Bitbucket Server --- .../com/cloudbees/jenkins/plugins/BitbucketJobProbe.java | 5 +++++ .../jenkins/plugins/BitbucketPayloadProcessor.java | 6 +----- .../jenkins/plugins/BitbucketPayloadProcessorTest.java | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/BitbucketJobProbe.java b/src/main/java/com/cloudbees/jenkins/plugins/BitbucketJobProbe.java index d8add285..45657684 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/BitbucketJobProbe.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/BitbucketJobProbe.java @@ -88,6 +88,11 @@ private boolean match(SCM scm, URIish url) { if (scm instanceof GitSCM) { for (RemoteConfig remoteConfig : ((GitSCM) scm).getRepositories()) { for (URIish urIish : remoteConfig.getURIs()) { + // needed cause the ssh and https URI differs in Bitbucket Server. + if(urIish.getPath().startsWith("/scm")){ + urIish = urIish.setPath(urIish.getPath().substring(4)); + } + LOGGER.log(Level.FINE, "Trying to match {0} ", urIish.toString() + "<-->" + url.toString()); if (GitStatus.looselyMatches(urIish, url)) { return true; } diff --git a/src/main/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessor.java b/src/main/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessor.java index a6b34b57..2c785958 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessor.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessor.java @@ -73,11 +73,7 @@ private void processWebhookPayloadBitBucketServer(JSONObject payload) { if (repo.getJSONObject("links").getJSONArray("self").size() != 0) { try { URL pushHref = new URL(repo.getJSONObject("links").getJSONArray("self").getJSONObject(0).getString("href")); - if (pushHref.getProtocol().equals("https")) { - url = pushHref.toString().replaceFirst(new String("projects.*"), new String("scm/" + repo.getString("fullName").toLowerCase())); - } else { - url = pushHref.toString().replaceFirst(new String("projects.*"), new String(repo.getString("fullName").toLowerCase())); - } + url = pushHref.toString().replaceFirst(new String("projects.*"), new String(repo.getString("fullName").toLowerCase())); String scm = repo.has("scmId") ? repo.getString("scmId") : "git"; probe.triggerMatchingJobs(user, url, scm, payload.toString()); } catch (MalformedURLException e) { diff --git a/src/test/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessorTest.java b/src/test/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessorTest.java index 6a5c4733..5e289ff9 100644 --- a/src/test/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessorTest.java +++ b/src/test/java/com/cloudbees/jenkins/plugins/BitbucketPayloadProcessorTest.java @@ -63,16 +63,16 @@ public void testProcessWebhookPayload() { @Test public void processWebhookPayloadBitBucketServer() { - // Set headers so that payload processor will parse as new Webhook payload when(request.getHeader("user-agent")).thenReturn("Apache-HttpClient/4.5.1 (Java/1.8.0_102)"); when(request.getHeader("x-event-key")).thenReturn("repo:push"); String user = "test_user"; - String url = "https://bitbucket.org/scm/ce/test_repo"; + String url = "https://bitbucket.org/ce/test_repo"; JSONObject href = new JSONObject(); href.element("href", "https://bitbucket.org/projects/CE/repos/test_repo/browse"); + // Set actor and repository so that payload processor will parse as Bitbucket Server Post Webhook payload JSONObject payload = new JSONObject() .element("actor", new JSONObject() .element("username", user)) From 982417785b527f8ed83580e40a570125aca8ebbd Mon Sep 17 00:00:00 2001 From: "fbelzunc@gmail.com" Date: Wed, 6 Dec 2017 21:18:28 +0100 Subject: [PATCH 10/12] [maven-release-plugin] prepare release bitbucket-1.1.8 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e0b1d081..87f00586 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ bitbucket - 1.1.8-SNAPSHOT + 1.1.8 hpi Jenkins Bitbucket Plugin integrate Jenkins with BitBucket. @@ -18,7 +18,7 @@ scm:git:git://github.com/jenkinsci/bitbucket-plugin.git scm:git:git@github.com:jenkinsci/bitbucket-plugin.git https://github.com/jenkinsci/bitbucket-plugin - HEAD + bitbucket-1.1.8 From ce068b7f2cbf5250aa6d54c3acdd455d45b56246 Mon Sep 17 00:00:00 2001 From: "fbelzunc@gmail.com" Date: Wed, 6 Dec 2017 21:18:35 +0100 Subject: [PATCH 11/12] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 87f00586..32571ba1 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ bitbucket - 1.1.8 + 1.1.9-SNAPSHOT hpi Jenkins Bitbucket Plugin integrate Jenkins with BitBucket. @@ -18,7 +18,7 @@ scm:git:git://github.com/jenkinsci/bitbucket-plugin.git scm:git:git@github.com:jenkinsci/bitbucket-plugin.git https://github.com/jenkinsci/bitbucket-plugin - bitbucket-1.1.8 + HEAD From 318fee07cc603bd920a963541b218f0fefaafb98 Mon Sep 17 00:00:00 2001 From: steven Date: Wed, 31 Oct 2018 09:19:01 -0400 Subject: [PATCH 12/12] Fixing a typo, adding message that a BitBucket 'Test connection' produces a message with no content --- .../com/cloudbees/jenkins/plugins/BitbucketHookReceiver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/BitbucketHookReceiver.java b/src/main/java/com/cloudbees/jenkins/plugins/BitbucketHookReceiver.java index 85990fe1..64e22530 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/BitbucketHookReceiver.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/BitbucketHookReceiver.java @@ -53,7 +53,7 @@ public void doIndex(StaplerRequest req) throws IOException { 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:///bitbucket-hook/`"); + LOGGER.log(Level.WARNING, "The Jenkins job cannot be triggered. You might not have configured correctly the WebHook on BitBucket with the last slash `http:///bitbucket-hook/` or a 'Test connection' invocation of the hook was triggered."); } }