jenkinsci / gitlab-plugin

A Jenkins plugin for interfacing with GitLab
https://plugins.jenkins.io/gitlab-plugin/
GNU General Public License v2.0
1.44k stars 613 forks source link

NPE in AbstractWebHookTriggerHandler.java:50 #550

Closed slauth closed 6 years ago

slauth commented 7 years ago

Issue

NPE in AbstractWebHookTriggerHandler.java:50

Context

Logs & Traces

/var/log/jenkins/jenkins.log

May 08, 2017 10:32:18 AM hudson.model.AsyncPeriodicWork$1 run
...skipping...
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
        at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:135)
        at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:126)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
        at com.dabsquared.gitlabjenkins.webhook.GitLabWebHook$GitlabWebHookCrumbExclusion.process(GitLabWebHook.java:53)
        at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:58)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84)
        at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:51)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at jenkins.security.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:117)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:135)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at jenkins.security.BasicHeaderProcessor.doFilter(BasicHeaderProcessor.java:93)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
        at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:67)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76)
        at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:171)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
        at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:49)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
        at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:82)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
        at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:553)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
        at org.eclipse.jetty.server.Server.handle(Server.java:499)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
        at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
        at winstone.BoundedExecutorService$1.run(BoundedExecutorService.java:77)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
        at com.dabsquared.gitlabjenkins.trigger.handler.AbstractWebHookTriggerHandler.handle(AbstractWebHookTriggerHandler.java:50)
        at com.dabsquared.gitlabjenkins.trigger.handler.push.PushHookTriggerHandlerImpl.handle(PushHookTriggerHandlerImpl.java:30)
        at com.dabsquared.gitlabjenkins.trigger.handler.push.PushHookTriggerHandlerImpl.handle(PushHookTriggerHandlerImpl.java:23)
        at com.dabsquared.gitlabjenkins.trigger.handler.push.PushHookTriggerHandlerList.handle(PushHookTriggerHandlerList.java:24)
        at com.dabsquared.gitlabjenkins.trigger.handler.push.PushHookTriggerHandlerList.handle(PushHookTriggerHandlerList.java:13)
        at com.dabsquared.gitlabjenkins.GitLabPushTrigger.onPost(GitLabPushTrigger.java:241)
        at com.dabsquared.gitlabjenkins.webhook.build.PushBuildAction$1.performOnPost(PushBuildAction.java:72)
        at com.dabsquared.gitlabjenkins.webhook.build.BuildWebHookAction$TriggerNotifier.run(BuildWebHookAction.java:54)
        at hudson.security.ACL.impersonate(ACL.java:243)
        at com.dabsquared.gitlabjenkins.webhook.build.PushBuildAction.execute(PushBuildAction.java:69)
        at com.dabsquared.gitlabjenkins.webhook.build.BuildWebHookAction.execute(BuildWebHookAction.java:31)
        at com.dabsquared.gitlabjenkins.webhook.GitLabWebHook.getDynamic(GitLabWebHook.java:44)
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
        at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:343)
        ... 61 more

Problem description

I'm currently trying to set up GitLab 9.1.2, Jenkins 2.46.2, GitLab Plugin 1.4.5 but getting an NPE in AbstractWebHookTriggerHandler.java:50. The job is a pipeline, the Jenkinsfile comes from SCM.

omehegan commented 7 years ago

Are you getting this error when a job is triggered? Can you show a snippet of your Jenkinsfile? Can you elaborate on how you have set up your GitLab webhooks? Is your Jenkins using authentication?

Please follow the README instructions under User Support to enable additional logging from the plugin, so we can see what it is doing.

slauth commented 7 years ago

Hi and thanks for looking into this. I'll try to answer your questions:

Are you getting this error when a job is triggered?

What I did is the following:

  1. Set everything up on GitLab and Jenkins side.
  2. Execute webhook by pressing the "Test" button in GitLab. Success.
  3. Push an empty commit to the repository. Nothing happens.
  4. Looking back into the Jenkins job config I see that the checkbox ("Build when a change is pushed to GitLab") is not checked any more. Strange. So I set this up again.
  5. Click this "Test" button again and I see the described Exception.

Can you show a snippet of your Jenkinsfile?

Here it is

Can you elaborate on how you have set up your GitLab webhooks?

Nothing special here. URL copied from "GitLab CI Service URL" section. Secret token created via "Generate" button. Checked "Push events", "Merge Request events" and "Enable SSL verification".

Is your Jenkins using authentication?

Yes it is. Local Jenkins users only.

Please follow the README instructions under User Support to enable additional logging from the plugin, so we can see what it is doing.

Here it is (some info obfuscated)

omehegan commented 7 years ago

The NPE is happening when we try to log the job name and trigger type: LOGGER.log(Level.INFO, "{0} triggered for {1}.", LoggerUtil.toArray(job.getFullName(), getTriggerType()));

So one of those values must be coming back null. Looking at the code, I don't see how getTriggerType can ever be null, it's just a protected string with different possible values. It might be that the job object is ending up null, and when you say that you saw the GitLab setting mysteriously unchecked in your Jenkins config, that's another clue. I don't know why that would be happening though.

Can you try triggering the job with an actual commit, rather than by using the Test webhook button?

slauth commented 7 years ago

Can you try triggering the job with an actual commit, rather than by using the Test webhook button?

Already tried that without success. Interestingly, freestyle and Maven jobs run fine.

omehegan commented 7 years ago

Not sure what to make of it. Let's leave this open, if you find any other clues please post them.

omehegan commented 7 years ago

Same exception in #546.

mhaas commented 7 years ago

FYI: I was seeing this exception today when setting up my first pipeline job. My Jenkinsfile too comes from SCM and I had neglected to set up the proper checkout parameters as described in https://github.com/jenkinsci/gitlab-plugin#git-configuration-for-freestyle-jobs - yes, that is the link to the description for freestyle jobs.

omehegan commented 6 years ago

@slauth were you ever able to resolve this issue? Does @mhaas's comment help?