gitlab-branch-source-plugin icon indicating copy to clipboard operation
gitlab-branch-source-plugin copied to clipboard

Error while serving <jenkins_url>/gitlab-webhook/post/

Open benoit-rolandeau-act opened this issue 1 year ago • 8 comments

Jenkins and plugins versions report

Environment
Jenkins version: 2.426.3
GitLab Branch Source Plugin version: 702.v7dde70ed1522
GitLab API Plugin version: 5.3.0-91.v1f9a_fda_d654f

GitLab self hosted version: v16.9.0

What Operating System are you using (both controller, and any agents involved in the problem)?

GitLab deployed with Docker Jenkins in a Debian VM

Reproduction steps

I configured my Jenkins like this:

image image

In the Pipeline Multibranches config:

image image image image

And in the GitLab project:

image image

I click on the GitLab test button:

image

Expected Results

I expect the test to work

Actual Results

In GitLab, I receive a 500 error.

And in Jenkins, I see the following logs:

Error processing event, exception=NullPointerException, error=Cannot invoke "String.equals(Object)" because the return value of "org.gitlab4j.api.webhook.MergeRequestEvent$ObjectAttributes.getAction()" is null

févr. 23, 2024 5:41:05 PM AVERTISSEMENT org.eclipse.jetty.server.handler.ContextHandler$Context log

Error while serving <jenkins_url>/gitlab-webhook/post/
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "org.gitlab4j.api.webhook.MergeRequestEvent$ObjectAttributes.getAction()" is null
	at io.jenkins.plugins.gitlabbranchsource.GitLabMergeRequestSCMEvent.typeOf(GitLabMergeRequestSCMEvent.java:31)
	at io.jenkins.plugins.gitlabbranchsource.GitLabMergeRequestSCMEvent.<init>(GitLabMergeRequestSCMEvent.java:24)
	at io.jenkins.plugins.gitlabbranchsource.GitLabMergeRequestTrigger.<init>(GitLabMergeRequestTrigger.java:15)
	at io.jenkins.plugins.gitlabbranchsource.GitLabWebHookListener.onMergeRequestEvent(GitLabWebHookListener.java:43)
	at org.gitlab4j.api.webhook.WebHookManager.fireMergeRequestEvent(WebHookManager.java:290)
	at org.gitlab4j.api.webhook.WebHookManager.fireEvent(WebHookManager.java:232)
	at org.gitlab4j.api.webhook.WebHookManager.handleRequest(WebHookManager.java:147)
Caused: org.gitlab4j.api.GitLabApiException: Cannot invoke "String.equals(Object)" because the return value of "org.gitlab4j.api.webhook.MergeRequestEvent$ObjectAttributes.getAction()" is null
	at org.gitlab4j.api.webhook.WebHookManager.handleRequest(WebHookManager.java:153)
	at org.gitlab4j.api.webhook.WebHookManager.handleEvent(WebHookManager.java:72)
	at io.jenkins.plugins.gitlabbranchsource.GitLabWebHookAction.doPost(GitLabWebHookAction.java:83)
	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:397)
Caused: java.lang.reflect.InvocationTargetException
	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:401)
	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:409)
	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:207)
	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:140)
	at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:558)
	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:59)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:770)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:900)
	at org.kohsuke.stapler.MetaClass$9.dispatch(MetaClass.java:475)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:770)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:900)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:698)
	at org.kohsuke.stapler.Stapler.service(Stapler.java:248)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
	at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1665)
	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:163)
	at org.jenkinsci.plugins.modernstatus.ModernStatusFilter.doFilter(ModernStatusFilter.java:50)
	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:160)
	at jenkins.util.HttpServletFilter$1.doFilter(HttpServletFilter.java:76)
	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:160)
	at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:166)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at jenkins.ErrorAttributeFilter.doFilter(ErrorAttributeFilter.java:29)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at io.jenkins.plugins.gitlabbranchsource.GitLabWebHookAction.process(GitLabWebHookAction.java:53)
	at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:128)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:94)
	at jenkins.security.AcegiSecurityExceptionFilter.doFilter(AcegiSecurityExceptionFilter.java:52)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:54)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:126)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:120)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:100)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:145)
	at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:101)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:227)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:221)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at jenkins.security.BasicHeaderProcessor.doFilter(BasicHeaderProcessor.java:97)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:117)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
	at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:63)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:111)
	at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:172)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:53)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:86)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at jenkins.security.SuspiciousRequestFilter.doFilter(SuspiciousRequestFilter.java:38)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:527)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:569)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:223)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1570)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1384)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1543)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1306)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at org.eclipse.jetty.server.Server.handle(Server.java:563)
	at org.eclipse.jetty.server.HttpChannel$RequestDispatchable.dispatch(HttpChannel.java:1598)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:753)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:501)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:287)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
	at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:969)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1194)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1149)
	at java.base/java.lang.Thread.run(Thread.java:840)

Anything else?

I don't know what cause the problem if it's caused by my config or a bug in the plugin itself.

Are you interested in contributing a fix?

No response

benoit-rolandeau-act avatar Feb 23 '24 17:02 benoit-rolandeau-act

Has any progress been made on this? We are seeing this issue as well

philip-bradshaw avatar Jul 10 '24 14:07 philip-bradshaw

Jenkins: Version 2.426.3, as a Docker container running in Kubernetes. Gitlab CE: Version 16.3.7, as a Docker container running in Kubernetes. GitLab API Plugin: Version 5.3.0-91.v1f9a_fda_d654f GitLab Branch Source Plugin: Version 704.vc7f1202d7e14

We're seeing the same thing.

mddelfino avatar Jul 15 '24 20:07 mddelfino

Hi @benoit-rolandeau-act and @mddelfino ,

Can you enable log of the plugin? There is an interesting log here : https://github.com/jenkinsci/gitlab-branch-source-plugin/blob/c7f1202d7e14fdf673eb1011722aeba8b52f2a5e/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabWebHookListener.java#L42

And can you give the payload of the MR event from Gitlab?

Turiok avatar Jul 20 '24 19:07 Turiok

If I'm not mistaken this is the expected log:

juil. 22, 2024 6:46:43 PM PRÉCIS io.jenkins.plugins.gitlabbranchsource.GitLabWebHookListener

{
  "object_kind" : "merge_request",
  "user" : {
    "avatarUrl" : "http://****:xxxx/uploads/-/system/user/avatar/2/avatar.png",
    "createdAt" : null,
    "email" : "[REDACTED]",
    "id" : 2,
    "name" : "xxxx xxxxx",
    "state" : null,
    "username" : "xxxxxxx",
    "webUrl" : null,
    "bio" : null,
    "bot" : null,
    "canCreateGroup" : null,
    "canCreateProject" : null,
    "colorSchemeId" : null,
    "confirmedAt" : null,
    "currentSignInAt" : null,
    "customAttributes" : null,
    "external" : null,
    "externUid" : null,
    "extraSharedRunnersMinutesLimit" : null,
    "identities" : null,
    "isAdmin" : null,
    "lastActivityOn" : null,
    "lastSignInAt" : null,
    "linkedin" : null,
    "location" : null,
    "organization" : null,
    "privateProfile" : null,
    "projectsLimit" : null,
    "provider" : null,
    "publicEmail" : null,
    "sharedRunnersMinutesLimit" : null,
    "skype" : null,
    "themeId" : null,
    "twitter" : null,
    "twoFactorEnabled" : null,
    "websiteUrl" : null,
    "skipConfirmation" : null
  },
  "project" : {
    "id" : 8,
    "name" : "ActQtToolbox",
    "description" : "",
    "webUrl" : "http://****:xxxx/internal-libraries/software/actqttoolbox",
    "avatarUrl" : "http://****:xxxx/uploads/-/system/project/avatar/8/langfr-220px-Qt_logo_2016.svg.png",
    "gitSshUrl" : "ssh://git@****:xxxx/internal-libraries/software/actqttoolbox.git",
    "gitHttpUrl" : "http://****:xxxx/internal-libraries/software/actqttoolbox.git",
    "namespace" : "Software",
    "visibilityLevel" : 0,
    "pathWithNamespace" : "internal-libraries/software/actqttoolbox",
    "defaultBranch" : "master",
    "ciConfigPath" : null,
    "homepage" : "http://****:xxxx/internal-libraries/software/actqttoolbox",
    "url" : "ssh://git@****:xxxx/internal-libraries/software/actqttoolbox.git",
    "sshUrl" : "ssh://git@****:xxxx/internal-libraries/software/actqttoolbox.git",
    "httpUrl" : "http://****:xxxx/internal-libraries/software/actqttoolbox.git"
  },
  "repository" : {
    "name" : "ActQtToolbox",
    "url" : "ssh://git@****:xxxx/internal-libraries/software/actqttoolbox.git",
    "description" : "",
    "homepage" : "http://****:xxxx/internal-libraries/software/actqttoolbox",
    "git_http_url" : null,
    "git_ssh_url" : null,
    "visibility_level" : null
  },
  "objectAttributes" : {
    "assigneeId" : 4,
    "authorId" : 4,
    "branchName" : null,
    "createdAt" : "2024-04-22T22:07:15.345Z",
    "description" : "",
    "id" : 3471,
    "iid" : 32,
    "mergeCommitSha" : "dd939687978193c1b733542c5f0d4c93b940d5fc",
    "mergeStatus" : "can_be_merged",
    "detailedMergeStatus" : "not_open",
    "milestoneId" : null,
    "position" : null,
    "lockedAt" : null,
    "projectId" : null,
    "sourceBranch" : "tmp/dssdsdsdsdsd",
    "sourceProjectId" : 8,
    "stCommits" : null,
    "stDiffs" : null,
    "state" : "merged",
    "stateId" : 3,
    "targetBranch" : "master",
    "targetProjectId" : 8,
    "title" : "master history split - refs #17689",
    "updatedAt" : "2024-04-23T07:58:12.547Z",
    "source" : {
      "id" : 8,
      "name" : "ActQtToolbox",
      "description" : "",
      "webUrl" : "http://****:xxxx/internal-libraries/software/actqttoolbox",
      "avatarUrl" : "http://****:xxxx/uploads/-/system/project/avatar/8/langfr-220px-Qt_logo_2016.svg.png",
      "gitSshUrl" : "ssh://****:xxxx/internal-libraries/software/actqttoolbox.git",
      "gitHttpUrl" : "http://****:xxxx/internal-libraries/software/actqttoolbox.git",
      "namespace" : "Software",
      "visibilityLevel" : 0,
      "pathWithNamespace" : "internal-libraries/software/actqttoolbox",
      "defaultBranch" : "master",
      "ciConfigPath" : null,
      "homepage" : "http://****:xxxx/internal-libraries/software/actqttoolbox",
      "url" : "ssh://git@****:xxxx/internal-libraries/software/actqttoolbox.git",
      "sshUrl" : "ssh://git@****:xxxx/internal-libraries/software/actqttoolbox.git",
      "httpUrl" : "http://****:xxxx/internal-libraries/software/actqttoolbox.git"
    },
    "target" : {
      "id" : 8,
      "name" : "ActQtToolbox",
      "description" : "",
      "webUrl" : "http://****:xxxx/internal-libraries/software/actqttoolbox",
      "avatarUrl" : "http://****:xxxx/uploads/-/system/project/avatar/8/langfr-220px-Qt_logo_2016.svg.png",
      "gitSshUrl" : "ssh://git@****:xxxx/internal-libraries/software/actqttoolbox.git",
      "gitHttpUrl" : "http://****:xxxx/internal-libraries/software/actqttoolbox.git",
      "namespace" : "Software",
      "visibilityLevel" : 0,
      "pathWithNamespace" : "internal-libraries/software/actqttoolbox",
      "defaultBranch" : "master",
      "ciConfigPath" : null,
      "homepage" : "http://****:xxxx/internal-libraries/software/actqttoolbox",
      "url" : "ssh://git@****:xxxx/internal-libraries/software/actqttoolbox.git",
      "sshUrl" : "ssh://git@****:xxxx/internal-libraries/software/actqttoolbox.git",
      "httpUrl" : "http://****:xxxx/internal-libraries/software/actqttoolbox.git"
    },
    "lastCommit" : {
      "id" : "dd939687978193c1b733542c5f0d4c93b940d5fc",
      "message" : "xqdf dffdf dfdf ",
      "timestamp" : "2024-04-22T21:46:47Z",
      "url" : "http://****:xxxx/internal-libraries/software/actqttoolbox/-/commit/dd939687978193c1b733542c5f0d4c93b940d5fc",
      "author" : {
        "avatarUrl" : null,
        "createdAt" : null,
        "email" : "[email protected]",
        "id" : null,
        "name" : "cccc cccc",
        "state" : null,
        "username" : null,
        "webUrl" : null
      },
      "added" : null,
      "modified" : null,
      "removed" : null
    },
    "blockingDiscussionsResolved" : false,
    "workInProgress" : false,
    "firstContribution" : false,
    "url" : "http://****:xxxx/internal-libraries/software/actqttoolbox/-/merge_requests/32",
    "labels" : [ ],
    "action" : null,
    "assignee" : null,
    "updatedById" : 2,
    "mergeError" : null,
    "mergeParams" : { },
    "mergeWhenPipelineSucceeds" : false,
    "mergeUserId" : null,
    "deletedAt" : null,
    "inProgressMergeCommitSha" : null,
    "lockVersion" : null,
    "lastEditedAt" : "2024-04-23T07:37:07.307Z",
    "lastEditedById" : 4,
    "headPipelineId" : 2003,
    "refFetched" : null,
    "mergeIid" : null,
    "totalTimeSpent" : 0,
    "humanTotalTimeSpent" : null,
    "timeChange" : 0,
    "timeEstimate" : 0,
    "humanTimeEstimate" : null,
    "humanTimeChange" : null,
    "assigneeIds" : [ 4 ],
    "reviewerIds" : [ 2 ],
    "oldrev" : null
  },
  "labels" : [ ],
  "changes" : {
    "authorId" : null,
    "createdAt" : null,
    "updatedAt" : null,
    "updatedById" : null,
    "title" : null,
    "description" : null,
    "state" : null,
    "milestoneId" : null,
    "labels" : null,
    "assignees" : null,
    "totalTimeSpent" : null,
    "mergeStatus" : null,
    "reviewers" : null
  },
  "assignees" : [ {
    "avatarUrl" : "http://****:xxxx/uploads/-/system/user/avatar/4/avatar.png",
    "createdAt" : null,
    "email" : "[REDACTED]",
    "id" : 4,
    "name" : "cccc ccccc",
    "state" : null,
    "username" : "ccccc",
    "webUrl" : null
  } ],
  "reviewers" : [ {
    "avatarUrl" : "http://****:xxxx/uploads/-/system/user/avatar/2/avatar.png",
    "createdAt" : null,
    "email" : "[REDACTED]",
    "id" : 2,
    "name" : "xxx xxxxx",
    "state" : null,
    "username" : "xxxxx",
    "webUrl" : null
  } ],
  "objectKind" : "merge_request"
}

benoit-rolandeau-act avatar Jul 22 '24 16:07 benoit-rolandeau-act

HI @benoit-rolandeau-act,

Sorry for the delay. I found the problem but doesn't know the solution because I don't know which behavior we want.

The error is here : https://github.com/jenkinsci/gitlab-branch-source-plugin/blob/6f19df32544b29c2c2904fbaed206a281335a33b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestSCMEvent.java#L31

You make a "merge request event" but on "merged" state depending on your payload. I don't know if it's a regular behavior? The first if in the "typeOf" method only check the "closed" state but for the second if. Your payload of action is null so an exception is raised.

@jetersen I would like your opinion on this? Depending the correct behavior. Is a "merged" MR should be triggered?

Yes, I propose this code :

private static Type typeOf(MergeRequestEvent mrEvent) {
        String action = mrEvent.getObjectAttributes().getAction();
        String state = mrEvent.getObjectAttributes().getState()
        if (state != null && state .equals("closed")) {
            return Type.REMOVED;
        } else if (action  != null && action .equals("open")) {
            return Type.CREATED;
        }
        return Type.UPDATED;
    }

No, I propose this code :

private static Type typeOf(MergeRequestEvent mrEvent) {
        String action = mrEvent.getObjectAttributes().getAction();
        String state = mrEvent.getObjectAttributes().getState()
        if (state != null && (state .equals("closed") || state.equals("merged")) {
            return Type.REMOVED;
        } else if (action  != null && action .equals("open")) {
            return Type.CREATED;
        }
        return Type.UPDATED;
    }

Be careful, I didn't test this code

Turiok avatar Sep 08 '24 09:09 Turiok

Is this resolved? We are seeing the same error today. All the GitLab merge request hooks are broken on jenkins.

dave105010 avatar Sep 25 '24 19:09 dave105010

HI @benoit-rolandeau-act,

Sorry for the delay. I found the problem but doesn't know the solution because I don't know which behavior we want.

The error is here :

https://github.com/jenkinsci/gitlab-branch-source-plugin/blob/6f19df32544b29c2c2904fbaed206a281335a33b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestSCMEvent.java#L31

You make a "merge request event" but on "merged" state depending on your payload. I don't know if it's a regular behavior? The first if in the "typeOf" method only check the "closed" state but for the second if. Your payload of action is null so an exception is raised.

@jetersen I would like your opinion on this? Depending the correct behavior. Is a "merged" MR should be triggered?

Yes, I propose this code :

private static Type typeOf(MergeRequestEvent mrEvent) {
        String action = mrEvent.getObjectAttributes().getAction();
        String state = mrEvent.getObjectAttributes().getState()
        if (state != null && state .equals("closed")) {
            return Type.REMOVED;
        } else if (action  != null && action .equals("open")) {
            return Type.CREATED;
        }
        return Type.UPDATED;
    }

No, I propose this code :

private static Type typeOf(MergeRequestEvent mrEvent) {
        String action = mrEvent.getObjectAttributes().getAction();
        String state = mrEvent.getObjectAttributes().getState()
        if (state != null && (state .equals("closed") || state.equals("merged")) {
            return Type.REMOVED;
        } else if (action  != null && action .equals("open")) {
            return Type.CREATED;
        }
        return Type.UPDATED;
    }

Be careful, I didn't test this code

Can this be solved with an option in the source configuration in the job settings?

WojTECs avatar Sep 30 '24 09:09 WojTECs

I fixed this for me for the time being by implementing the proposed changes by @Turiok like this:

private static Type typeOf(MergeRequestEvent mrEvent) {
        if ("closed".equals(mrEvent.getObjectAttributes().getState())) {
            return Type.REMOVED;
        } else if ("open".equals(mrEvent.getObjectAttributes().getAction())) {
            return Type.CREATED;
        }
        return Type.UPDATED;
    }

I have no idea if these changes are okay or if there is something logically wrong with doing this, as I don't have experience coding here and only use the plugin.

  • I then recompiled the plugin with the instructions on the Project README
  • Removed the normally installed plugin from Jenkins (make sure somehow to save the Global and Project GitLab plugin settings, as the project settings are removed)
  • Installed the recompiled plugin manually with the compiled .hpi file to Jenkins

It's working for now for me and MR webhooks don't throw an error anymore.

filo14 avatar Oct 18 '24 13:10 filo14