-
Notifications
You must be signed in to change notification settings - Fork 98
Correction of rebuild on comment on wrong pipeline #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import java.util.regex.Pattern; | ||
import jenkins.branch.MultiBranchProject; | ||
import jenkins.model.ParameterizedJobMixIn; | ||
import jenkins.scm.api.SCMHeadObserver; | ||
import jenkins.scm.api.SCMSource; | ||
|
@@ -56,29 +57,33 @@ public void isMatch() { | |
if (gitLabSCMSource.getProjectId() == getPayload().getMergeRequest().getTargetProjectId() | ||
&& isTrustedMember(gitLabSCMSource, sourceContext.getOnlyTrustedMembersCanTrigger())) { | ||
for (Job<?, ?> job : owner.getAllJobs()) { | ||
if (mergeRequestJobNamePattern.matcher(job.getName()).matches()) { | ||
String expectedCommentBody = sourceContext.getCommentBody(); | ||
Pattern pattern = Pattern.compile(expectedCommentBody, | ||
Pattern.CASE_INSENSITIVE | Pattern.DOTALL); | ||
if (commentBody == null || pattern.matcher(commentBody) | ||
.matches()) { | ||
ParameterizedJobMixIn.scheduleBuild2(job, 0, | ||
new CauseAction( | ||
new GitLabMergeRequestCommentCause(commentUrl, getPayload()))); | ||
LOGGER.log(Level.INFO, | ||
"Triggered build for {0} due to MR comment on {1}", | ||
new Object[] { | ||
job.getFullName(), | ||
getPayload().getProject().getPathWithNamespace() | ||
}); | ||
} else { | ||
LOGGER.log(Level.INFO, | ||
"MR comment does not match the trigger build string ({0}) for {1}", | ||
new Object[] { expectedCommentBody, job.getFullName() }); | ||
if (MultiBranchProject.class.isAssignableFrom(job.getParent().getClass()) ) { | ||
MultiBranchProject parentJob = (MultiBranchProject) job.getParent(); | ||
if (parentJob.getSCMSource(gitLabSCMSource.getId()) == gitLabSCMSource | ||
Comment on lines
+60
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I try to check the link between the source of the payload and the job in the for. I don't know if there is a better solution |
||
&& mergeRequestJobNamePattern.matcher(job.getName()).matches()) { | ||
String expectedCommentBody = sourceContext.getCommentBody(); | ||
Pattern pattern = Pattern.compile(expectedCommentBody, | ||
Pattern.CASE_INSENSITIVE | Pattern.DOTALL); | ||
if (commentBody == null || pattern.matcher(commentBody) | ||
.matches()) { | ||
ParameterizedJobMixIn.scheduleBuild2(job, 0, | ||
new CauseAction( | ||
new GitLabMergeRequestCommentCause(commentUrl, getPayload()))); | ||
LOGGER.log(Level.INFO, | ||
"Triggered build for {0} due to MR comment on {1}", | ||
new Object[] { | ||
job.getFullName(), | ||
getPayload().getProject().getPathWithNamespace() | ||
}); | ||
} else { | ||
LOGGER.log(Level.INFO, | ||
"MR comment does not match the trigger build string ({0}) for {1}", | ||
new Object[] { expectedCommentBody, job.getFullName() }); | ||
} | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this break, only one job can be executed. I'm wondering if it is possible to have 2 multi branch pipelines with the same project? |
||
} | ||
break; | ||
jobFound = true; | ||
} | ||
jobFound = true; | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this for, we loop to all jobs. Even out of the projectId. And there isn't more check after with the payload