Skip to content

Commit 66cdf19

Browse files
committed
Correction of #256
filtered jenkins jobs with SCMSource of the payload on comment trigger
1 parent dee7766 commit 66cdf19

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.util.logging.Level;
99
import java.util.logging.Logger;
1010
import java.util.regex.Pattern;
11+
12+
import jenkins.branch.MultiBranchProject;
1113
import jenkins.model.ParameterizedJobMixIn;
1214
import jenkins.scm.api.SCMHeadObserver;
1315
import jenkins.scm.api.SCMSource;
@@ -56,29 +58,33 @@ public void isMatch() {
5658
if (gitLabSCMSource.getProjectId() == getPayload().getMergeRequest().getTargetProjectId()
5759
&& isTrustedMember(gitLabSCMSource, sourceContext.getOnlyTrustedMembersCanTrigger())) {
5860
for (Job<?, ?> job : owner.getAllJobs()) {
59-
if (mergeRequestJobNamePattern.matcher(job.getName()).matches()) {
60-
String expectedCommentBody = sourceContext.getCommentBody();
61-
Pattern pattern = Pattern.compile(expectedCommentBody,
62-
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
63-
if (commentBody == null || pattern.matcher(commentBody)
64-
.matches()) {
65-
ParameterizedJobMixIn.scheduleBuild2(job, 0,
66-
new CauseAction(
67-
new GitLabMergeRequestCommentCause(commentUrl, getPayload())));
68-
LOGGER.log(Level.INFO,
69-
"Triggered build for {0} due to MR comment on {1}",
70-
new Object[] {
71-
job.getFullName(),
72-
getPayload().getProject().getPathWithNamespace()
73-
});
74-
} else {
75-
LOGGER.log(Level.INFO,
76-
"MR comment does not match the trigger build string ({0}) for {1}",
77-
new Object[] { expectedCommentBody, job.getFullName() });
61+
if (MultiBranchProject.class.isAssignableFrom(job.getParent().getClass()) ) {
62+
MultiBranchProject parentJob = (MultiBranchProject) job.getParent();
63+
if (parentJob.getSCMSource(gitLabSCMSource.getId()) == gitLabSCMSource
64+
&& mergeRequestJobNamePattern.matcher(job.getName()).matches()) {
65+
String expectedCommentBody = sourceContext.getCommentBody();
66+
Pattern pattern = Pattern.compile(expectedCommentBody,
67+
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
68+
if (commentBody == null || pattern.matcher(commentBody)
69+
.matches()) {
70+
ParameterizedJobMixIn.scheduleBuild2(job, 0,
71+
new CauseAction(
72+
new GitLabMergeRequestCommentCause(commentUrl, getPayload())));
73+
LOGGER.log(Level.INFO,
74+
"Triggered build for {0} due to MR comment on {1}",
75+
new Object[] {
76+
job.getFullName(),
77+
getPayload().getProject().getPathWithNamespace()
78+
});
79+
} else {
80+
LOGGER.log(Level.INFO,
81+
"MR comment does not match the trigger build string ({0}) for {1}",
82+
new Object[] { expectedCommentBody, job.getFullName() });
83+
}
84+
break;
7885
}
79-
break;
86+
jobFound = true;
8087
}
81-
jobFound = true;
8288
}
8389
}
8490
}

0 commit comments

Comments
 (0)