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))