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 By Branch" Not working #702

Closed LahariGuntha closed 6 years ago

LahariGuntha commented 6 years ago

Hi,

I want to trigger a job in Jenkins whenever there is a code change that is pushed to a branch...Not master or any other branches... I was trying to Use Gitlab plugin of version-1.5.4... My jenkins is of version - 2.46.3 Job Type-Pipeline

But it is throwing Error like :

java.lang.IllegalStateException: This project does not use git:Svcdevelopment
    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:548)
    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:126)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:49)
    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: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:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

jenkinserr

LahariGuntha commented 6 years ago

Here my branch is "svcdev"...I want to trigger a job only when the change is pushed to "svcdev" branch only...I also have other branches...like svcdev1,master etc...Job should not be trigerred when the change is pushed to master or "svcdev1" branch

LahariGuntha commented 6 years ago

Could someone please look into this Issue??

karlgb commented 6 years ago

It appears that branch cannot be found. Check the job settings under the Source Code Management section in Jenkins to confirm you have the correct repo URL, name, etc. There are several dependent settings that could be relevant here. I had a similar issue and ended up filtering the branch name via regex which also helped.

omehegan commented 6 years ago

@LahariGuntha yes, please double-check your git SCM settings as @karlgb suggested. If they are definitely OK, please try the regex filter instead of branch name filter and let me know if that works. If so there may be a bug in the branch name filtering. Thanks.

LahariGuntha commented 6 years ago

Hi,

I have the following below configuration: I have created a "Pipeline" project.

So I have the below configuration: svc1

I have given the name to the pipeline...and have passed some parameters to the build...

I have tried "Filter by Branch"...But it was not working... So I thought of trying "Filter by Regular Expression": I have "Regular Expression"

(..) Under the "Build Triggers" I have the following Configuration: svc2

I have created "Access Token" in Gitlab and added it here...as shown below.. svc3

Here is my final config: svc5

I have given my Git URL...Branches to build...

Now...even when I change my code in master then also the build is getting triggered. Should there be any change in my Jenkins configuration???

LahariGuntha commented 6 years ago

Even "Filter by Regex" is not working here..

omehegan commented 6 years ago

@LahariGuntha for one thing, your access token is set up incorrectly. You do not want to check "trigger builds from scripts." You want to enter the access token in the Jenkins Credentials interface. Please re-read the README for the steps on how to do that. However that API key is only needed for sending build status back to GitLab. It is unrelated to the branch filtering issue.

omehegan commented 6 years ago

Can you share your pipeline code where you actually clone the git repo? The plugin will show an error for a branch name filter before the first time the job is run, because it does not yet know what branches exist in the repo.

LahariGuntha commented 6 years ago

Hi,

I just removed the "Trigger builds from scripts" and I used "Regex" ..Now it is working.. Thanks for the Support