|
8 | 8 | import java.util.logging.Level; |
9 | 9 | import java.util.logging.Logger; |
10 | 10 | import java.util.regex.Pattern; |
| 11 | + |
| 12 | +import jenkins.branch.MultiBranchProject; |
11 | 13 | import jenkins.model.ParameterizedJobMixIn; |
12 | 14 | import jenkins.scm.api.SCMHeadObserver; |
13 | 15 | import jenkins.scm.api.SCMSource; |
@@ -56,29 +58,33 @@ public void isMatch() { |
56 | 58 | if (gitLabSCMSource.getProjectId() == getPayload().getMergeRequest().getTargetProjectId() |
57 | 59 | && isTrustedMember(gitLabSCMSource, sourceContext.getOnlyTrustedMembersCanTrigger())) { |
58 | 60 | 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; |
78 | 85 | } |
79 | | - break; |
| 86 | + jobFound = true; |
80 | 87 | } |
81 | | - jobFound = true; |
82 | 88 | } |
83 | 89 | } |
84 | 90 | } |
|
0 commit comments