Skip to content

Commit 77f4f22

Browse files
committed
BitbucketJobProbe: Support BitbucketSCMSource for job matching
Extend the plugin to support the BitbucketSCMSource. This allow to trigger build coming from this source Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
1 parent 7284e93 commit 77f4f22

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999
<groupId>org.jenkins-ci.plugins.workflow</groupId>
100100
<artifactId>workflow-multibranch</artifactId>
101101
</dependency>
102+
<dependency>
103+
<groupId>org.jenkins-ci.plugins</groupId>
104+
<artifactId>cloudbees-bitbucket-branch-source</artifactId>
105+
</dependency>
102106

103107
<dependency>
104108
<groupId>org.jenkins-ci.plugins</groupId>

src/main/java/com/cloudbees/jenkins/plugins/BitbucketJobProbe.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.eclipse.jgit.transport.URIish;
3434
import com.google.common.base.Objects;
3535
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
36+
import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource;
3637

3738
public class BitbucketJobProbe {
3839

@@ -216,10 +217,19 @@ private boolean match(SCM scm, URIish url, String overrideUrl) {
216217
}
217218

218219
private boolean match(SCMSource scm, URIish url) {
219-
if (scm instanceof GitSCMSource) {
220-
LOGGER.log(Level.FINEST, "SCMSource is GitSCMSource");
221-
String gitRemote = ((GitSCMSource) scm).getRemote();
220+
if (scm instanceof GitSCMSource || scm instanceof BitbucketSCMSource) {
221+
String gitRemote;
222+
if (scm instanceof GitSCMSource) {
223+
LOGGER.log(Level.FINEST, "SCMSource is GitSCMSource");
224+
gitRemote = ((GitSCMSource) scm).getRemote();
225+
} else {
226+
LOGGER.log(Level.FINEST, "SCMSource is BitbucketSCMSource");
227+
gitRemote = ((BitbucketSCMSource) scm).getServerUrl() + "/" +
228+
((BitbucketSCMSource) scm).getRepoOwner() + "/" +
229+
((BitbucketSCMSource) scm).getRepository();
230+
}
222231
URIish urIish;
232+
LOGGER.log(Level.FINEST, "SCMSource remote is " + gitRemote);
223233
try {
224234
urIish = new URIish(gitRemote);
225235
} catch (URISyntaxException e) {

0 commit comments

Comments
 (0)