diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java index eedd8783..46a02855 100644 --- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java +++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java @@ -52,8 +52,10 @@ public void isMatch() { if (!sourceContext.mrCommentTriggerEnabled()) { continue; } - if (gitLabSCMSource.getProjectId() - == getPayload().getMergeRequest().getTargetProjectId() + Long projectId = gitLabSCMSource.getProjectId(); + if (projectId != null + && projectId.equals( + getPayload().getMergeRequest().getTargetProjectId()) && isTrustedMember(gitLabSCMSource, sourceContext.getOnlyTrustedMembersCanTrigger())) { for (Job job : owner.getAllJobs()) { if (MultiBranchProject.class.isAssignableFrom( diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java index 295bb51e..f3019535 100644 --- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java +++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java @@ -237,12 +237,12 @@ public HashMap getMembers() { return members; } - public long getProjectId() { + public Long getProjectId() { return projectId; } @DataBoundSetter - public void setProjectId(long projectId) { + public void setProjectId(Long projectId) { this.projectId = projectId; } diff --git a/src/test/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceDeserializationTest.java b/src/test/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceDeserializationTest.java index 2c965e4f..4326b01e 100644 --- a/src/test/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceDeserializationTest.java +++ b/src/test/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceDeserializationTest.java @@ -1,5 +1,6 @@ package io.jenkins.plugins.gitlabbranchsource; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.lang.reflect.Field; @@ -43,4 +44,25 @@ public void afterRestartingJenkinsTransientFieldsAreNotNull() throws Exception { assertNotNull(mergeRequestContributorCache.get(source)); }); } + + @Test + public void projectIdSurvivesConfigRoundtrip() { + plan.then(j -> { + GitLabSCMSourceBuilder sb = + new GitLabSCMSourceBuilder(SOURCE_ID, "server", "creds", "po", "group/project", "project"); + WorkflowMultiBranchProject project = j.createProject(WorkflowMultiBranchProject.class, PROJECT_NAME); + GitLabSCMSource source = sb.build(); + project.getSourcesList().add(new BranchSource(source)); + long p = 42; + source.setProjectId(p); + j.configRoundtrip(project); + + WorkflowMultiBranchProject item = + j.jenkins.getItemByFullName(PROJECT_NAME, WorkflowMultiBranchProject.class); + assertNotNull(item); + GitLabSCMSource scmSource = (GitLabSCMSource) item.getSCMSource(SOURCE_ID); + assertNotNull(scmSource); + assertEquals(Long.valueOf(p), scmSource.getProjectId()); + }); + } }