|
8 | 8 | import java.util.logging.Level;
|
9 | 9 | import java.util.logging.Logger;
|
10 | 10 | import java.util.regex.Pattern;
|
| 11 | +import jenkins.branch.MultiBranchProject; |
11 | 12 | import jenkins.model.ParameterizedJobMixIn;
|
12 | 13 | import jenkins.scm.api.SCMHeadObserver;
|
13 | 14 | import jenkins.scm.api.SCMSource;
|
@@ -56,29 +57,33 @@ public void isMatch() {
|
56 | 57 | if (gitLabSCMSource.getProjectId() == getPayload().getMergeRequest().getTargetProjectId()
|
57 | 58 | && isTrustedMember(gitLabSCMSource, sourceContext.getOnlyTrustedMembersCanTrigger())) {
|
58 | 59 | 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() }); |
| 60 | + if (MultiBranchProject.class.isAssignableFrom(job.getParent().getClass()) ) { |
| 61 | + MultiBranchProject parentJob = (MultiBranchProject) job.getParent(); |
| 62 | + if (parentJob.getSCMSource(gitLabSCMSource.getId()) == gitLabSCMSource |
| 63 | + && mergeRequestJobNamePattern.matcher(job.getName()).matches()) { |
| 64 | + String expectedCommentBody = sourceContext.getCommentBody(); |
| 65 | + Pattern pattern = Pattern.compile(expectedCommentBody, |
| 66 | + Pattern.CASE_INSENSITIVE | Pattern.DOTALL); |
| 67 | + if (commentBody == null || pattern.matcher(commentBody) |
| 68 | + .matches()) { |
| 69 | + ParameterizedJobMixIn.scheduleBuild2(job, 0, |
| 70 | + new CauseAction( |
| 71 | + new GitLabMergeRequestCommentCause(commentUrl, getPayload()))); |
| 72 | + LOGGER.log(Level.INFO, |
| 73 | + "Triggered build for {0} due to MR comment on {1}", |
| 74 | + new Object[] { |
| 75 | + job.getFullName(), |
| 76 | + getPayload().getProject().getPathWithNamespace() |
| 77 | + }); |
| 78 | + } else { |
| 79 | + LOGGER.log(Level.INFO, |
| 80 | + "MR comment does not match the trigger build string ({0}) for {1}", |
| 81 | + new Object[] { expectedCommentBody, job.getFullName() }); |
| 82 | + } |
| 83 | + break; |
78 | 84 | }
|
79 |
| - break; |
| 85 | + jobFound = true; |
80 | 86 | }
|
81 |
| - jobFound = true; |
82 | 87 | }
|
83 | 88 | }
|
84 | 89 | }
|
|
0 commit comments