timja / jenkins-gh-issues-poc-06-18

0 stars 0 forks source link

[JENKINS-16610] Unable to use variables for polling SCM Cron when using template workflow plugin #2861

Open timja opened 11 years ago

timja commented 11 years ago

I am current making use of the template workflow plugin which quite nicely allows you to define a workflow out a set of template jobs and then have specific instances of these workflows and new jobs created based on the template.

The plugin allows you to mark a job as a "template job". Within this template job, in order to provide for template based variable substitution, it expects you to specify variables in the form of @@VAR_NAME@@, which when the plugin runs, will substitute these values for specific values defined for each workflow instance.

The issue is that this works fine for most areas where @@VAR_NAME@@ type variables are defined, for example in the "description" and even in the "Repository URL" field for subversion. Although a red UI error message is displayed, you are still able to save the template. Unfortunately when trying to use the @@VAR_NAME@@ format in the Polling SCM field, an exception is thrown upon saving and the template cannot be saved.

The exception is as follows

Status Code: 500
Exception: java.lang.RuntimeException: Failed to instantiate class hudson.triggers.SCMTrigger from {"ignorePostCommitHooks":false,"scmpoll_spec":"@@J_SCM_POLLING_CRON@@"}
Stacktrace:

javax.servlet.ServletException: java.lang.RuntimeException: Failed to instantiate class hudson.triggers.SCMTrigger from {"ignorePostCommitHooks":false,"scmpoll_spec":"@@J_SCM_POLLING_CRON@@"}
    at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:615)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:658)
    at org.kohsuke.stapler.MetaClass$6.doDispatch(MetaClass.java:241)
    at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
    at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:573)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:658)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:487)
    at org.kohsuke.stapler.Stapler.service(Stapler.java:164)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:95)
    at hudson.plugins.greenballs.GreenBallFilter.doFilter(GreenBallFilter.java:58)
    at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:98)
    at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:206)
    at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:179)
    at net.bull.javamelody.PluginMonitoringFilter.doFilter(PluginMonitoringFilter.java:86)
    at org.jvnet.hudson.plugins.monitoring.HudsonMonitoringFilter.doFilter(HudsonMonitoringFilter.java:84)
    at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:98)
    at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:87)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:47)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    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 org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:166)
    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 org.acegisecurity.ui.basicauth.BasicProcessingFilter.doFilter(BasicProcessingFilter.java:173)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at jenkins.security.ApiTokenFilter.doFilter(ApiTokenFilter.java:63)
    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:66)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76)
    at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:164)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:50)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:81)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
    at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.RuntimeException: Failed to instantiate class hudson.triggers.SCMTrigger from {"ignorePostCommitHooks":false,"scmpoll_spec":"@@J_SCM_POLLING_CRON@@"}
    at hudson.model.Descriptor.newInstance(Descriptor.java:602)
    at hudson.model.AbstractProject.buildDescribable(AbstractProject.java:1897)
    at hudson.model.AbstractProject.submit(AbstractProject.java:1876)
    at hudson.maven.MavenModuleSet.submit(MavenModuleSet.java:1115)
    at hudson.model.Job.doConfigSubmit(Job.java:1046)
    at hudson.model.AbstractProject.doConfigSubmit(AbstractProject.java:723)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:288)
    at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:151)
    at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:90)
    at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:111)
    at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
    at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:573)
    ... 66 more
Caused by: java.lang.IllegalArgumentException: Failed to instantiate class hudson.triggers.SCMTrigger from {"ignorePostCommitHooks":false,"scmpoll_spec":"@@J_SCM_POLLING_CRON@@"}
    at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:582)
    at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:377)
    at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:373)
    at hudson.model.Descriptor.newInstance(Descriptor.java:593)
    ... 81 more
Caused by: java.lang.IllegalArgumentException: antlr.ANTLRException: Invalid input: "@@J_SCM_POLLING_CRON@@": line 1:2: unexpected token: @
    at org.kohsuke.stapler.RequestImpl.invokeConstructor(RequestImpl.java:439)
    at org.kohsuke.stapler.RequestImpl.access$200(RequestImpl.java:76)
    at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:580)
    ... 84 more
Caused by: antlr.ANTLRException: Invalid input: "@@J_SCM_POLLING_CRON@@": line 1:2: unexpected token: @
    at hudson.scheduler.CronTabList.create(CronTabList.java:87)
    at hudson.scheduler.CronTabList.create(CronTabList.java:73)
    at hudson.triggers.Trigger.(Trigger.java:161)
    at hudson.triggers.SCMTrigger.(SCMTrigger.java:85)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.kohsuke.stapler.RequestImpl.invokeConstructor(RequestImpl.java:424)
    ... 86 more
Caused by: line 1:2: unexpected token: @
    at hudson.scheduler.CrontabParser.startRule(CrontabParser.java:157)
    at hudson.scheduler.CronTab.set(CronTab.java:90)
    at hudson.scheduler.CronTab.(CronTab.java:80)
    at hudson.scheduler.CronTabList.create(CronTabList.java:85)
    ... 94 more

Obviously @@J_SCM_POLLING_CRON@@ is not valid cron syntax, hence the error, however this is just a template job. The real job would have a valid definition in it.

I was hoping that a solution to this could be that upon saving a job with such a definition, in the same way that an invalid value in the "Repository URL" yields a UI error and warning, but still allows the value to be saved, this could do a similar thing? As this template job is never going to run anyway, it doesn't matter that it has invalid definitions. Or if anybody else has any other ideas/suggestions I would be open to them too


Originally reported by nickithewatt, imported from: Unable to use variables for polling SCM Cron when using template workflow plugin
  • status: Open
  • priority: Major
  • resolution: Unresolved
  • imported: 2022/01/10
timja commented 10 years ago

oleg_nenashev:

I suppose you could just create a custom "Cron" entry in your plugin.
Is there any need to break the field validation functionality in the core?