Skip to content
Permalink
Browse files
Merge pull request #20 from fbelzunc/JENKINS-30985
[FIXED JENKINS-30985] Trigger only one build per same scm
  • Loading branch information
fbelzunc committed Oct 16, 2015
2 parents e20b8b3 + a49bbda commit 610593ff8cd3572ea6834c217da17999c0dc9c54
Showing with 14 additions and 2 deletions.
  1. +14 −2 src/main/java/com/cloudbees/jenkins/plugins/BitbucketJobProbe.java
@@ -7,6 +7,8 @@
import hudson.security.ACL;

import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

@@ -43,10 +45,11 @@ public void triggerMatchingJobs(String user, String url, String scm) {
if (bTrigger != null) {
LOGGER.log(Level.FINE, "Considering to poke {0}", job.getFullDisplayName());
SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job);

List<SCM> scmTriggered = new ArrayList<SCM>();
for (SCM scmTrigger : item.getSCMs()) {
if (match(scmTrigger, remote)) {
if (match(scmTrigger, remote) && !hasBeenTriggered(scmTriggered, scmTrigger)) {
LOGGER.log(Level.INFO, "Triggering BitBucket job {0}", job.getName());
scmTriggered.add(scmTrigger);
bTrigger.onPost(user);
} else LOGGER.log(Level.FINE, "{0} SCM doesn't match remote repo {1}", new Object[]{job.getName(), remote});
}
@@ -65,6 +68,15 @@ public void triggerMatchingJobs(String user, String url, String scm) {
}
}

private boolean hasBeenTriggered(List<SCM> scmTriggered, SCM scmTrigger) {
for (SCM scm : scmTriggered) {
if (scm.equals(scmTrigger)) {
return true;
}
}
return false;
}

private boolean match(SCM scm, URIish url) {
if (scm instanceof GitSCM) {
for (RemoteConfig remoteConfig : ((GitSCM) scm).getRepositories()) {

0 comments on commit 610593f

Please sign in to comment.