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

"Filter branches by name" does not pull branches when using a custom workspace #606

Closed zlippard closed 6 years ago

zlippard commented 7 years ago

Issue

I have two jobs set up in Jenkins. One, called 'android_source', which downloads my gitlab Android project and holds the source code and another, called 'android_beta', which sets the custom workspace to 'android_source' and attempts to build against it to create a beta APK. I also have a configuration set up in 'android_beta' to only run when changes are pushed to a branch called develop. However, the configuration errors out when attempting to put any text in the Include field. See below for the stack trace and image of the issue.

If I copy the Source Code Management git settings from 'android_source' in to 'android_beta' and remove the custom workspace configuration, then the error goes away.

I believe the "Filter branches by name" feature needs to be updated to support custom workspaces.

Context

Images & Traces

Image of error:

screen shot 2017-08-18 at 2 09 07 pm

Stack Trace:

java.lang.IllegalStateException: This project does not use git:android_beta
    at com.dabsquared.gitlabjenkins.trigger.branch.ProjectBranchesProvider.getSourceRepoURLDefault(ProjectBranchesProvider.java:130)
    at com.dabsquared.gitlabjenkins.trigger.branch.ProjectBranchesProvider.getProjectBranches(ProjectBranchesProvider.java:45)
    at com.dabsquared.gitlabjenkins.trigger.branch.ProjectBranchesProvider.doCheckBranchesSpec(ProjectBranchesProvider.java:76)
    at com.dabsquared.gitlabjenkins.GitLabPushTrigger$DescriptorImpl.doCheckIncludeBranchesSpec(GitLabPushTrigger.java:393)
    at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
    at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:343)
    at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:184)
    at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:117)
    at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:129)
    at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
    at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:715)
Caused: javax.servlet.ServletException
    at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:765)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:845)
    at org.kohsuke.stapler.MetaClass$5.doDispatch(MetaClass.java:248)
    at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
    at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:715)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:845)
    at org.kohsuke.stapler.MetaClass$5.doDispatch(MetaClass.java:248)
    at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
    at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:715)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:845)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)
    at org.kohsuke.stapler.Stapler.service(Stapler.java:238)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
    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:138)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:86)
    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:142)
    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:92)
    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:90)
    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:745)
omehegan commented 7 years ago

Thanks for this issue report, it does look like a bug. The stack trace you included looks like it is missing a couple of lines, can you just update that so it's complete?

zlippard commented 7 years ago

Sure thing, fixed the stack trace. Thanks!

omehegan commented 7 years ago

Thanks. Can you also either post some more screen shots of your configuration, or attach a sanitized config.xml for the job? I'm not 100% sure I understand what you're doing in the config.

zlippard commented 7 years ago

Attached is the XML file and extra screenshots.

android_beta_config_xml.txt

screen shot 2017-09-01 at 7 14 26 pm screen shot 2017-09-01 at 7 14 43 pm screen shot 2017-09-01 at 7 14 57 pm
omehegan commented 7 years ago

How is this going to work without any Git SCM configured? I'm going to guess that's why you get this error... I think Jenkins wants to confirm that the branch you're specifying actually exists in the repo.

omehegan commented 7 years ago

Re-reading your original issue post... I don't think I would advise you to use this pattern. Can you explain why you don't do the clone and build all in the same Jenkins job?

zlippard commented 7 years ago

Apologies for the delayed reply. The thought was that I would use one job to clone and build the repo and then other jobs could use the first job's workspace for running tests, beta builds, release builds, etc off of that workspace. This way I wouldn't have to clone the repo separately in to each work space and I could cut down the number of steps in each job.

omehegan commented 7 years ago

@zlippard I would say that in my experience with Jenkins, what you are suggesting is kind of an anti-pattern. It can seem appealing to reduce steps in jobs, but IMO the workspace should almost never be shared across jobs.

For these and other reasons, I would always discourage people from having jobs share a workspace.

zlippard commented 6 years ago

@omehegan gotcha. That's what I ended up doing. Longer term, I wouldn't want to use the same workspace for shared code in case there are concurrent jobs running that need to do tests, perhaps on different branches of the codebase. It makes more sense to have each job hold on to the code. Thanks for the help! Will close this ticket.