File as parameter not working

4,340 views
Skip to first unread message

Jonathan Hodgson

unread,
May 17, 2016, 1:11:15 PM5/17/16
to Jenkins Users
Hi,

I'm running Jenkins on Debian, still very new to it. I'm currently trying to set up a pipeline job... just a test one so I can make sure the structure I have in mind works.

Anyway, part of the requirement is to upload a file, so I've made the build parameterized, and added a "File as Parameter" parameter.

When I "Build using parameters", selecting an example file (just a simple text file for the moment)...

1) The file doesn't seem to be uploaded into the workspace
2) When I select it on the "view parameters" page for that build, I get an error

javax.servlet.ServletException: java.lang.NullPointerException
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:796)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
	at org.kohsuke.stapler.MetaClass$5.doDispatch(MetaClass.java:233)
	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
	at org.kohsuke.stapler.MetaClass$11.dispatch(MetaClass.java:380)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
	at org.kohsuke.stapler.MetaClass$11.dispatch(MetaClass.java:380)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
	at org.kohsuke.stapler.MetaClass$5.doDispatch(MetaClass.java:233)
	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
	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 org.jenkinsci.plugins.modernstatus.ModernStatusFilter.doFilter(ModernStatusFilter.java:52)
	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:132)
	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.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:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
	at hudson.model.FileParameterValue.doDynamic(FileParameterValue.java:205)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:324)
	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:167)
	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:100)
	at org.kohsuke.stapler.MetaClass$12.dispatch(MetaClass.java:403)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
	... 55 more

Before I submit a bug report I'd like to check that I'm not doing anything silly. As an experiment I tried changing the permissions on the workspace and subfolders to full access to everyone, in case it was a permissions issue (perhaps something I hadn't configured correctly), but that made no difference.

regards

Jon

Jonathan Hodgson

unread,
May 18, 2016, 1:21:11 AM5/18/16
to Jenkins Users
I've been experimenting, and if I do what appears to be exactly the same thing with a Freestyle project, file upload is successful.

I can't state yet whether the freestyle/pipeline job difference coinciding with a failure to upload the file is a coincidence, or the deciding factor.

Jonathan Hodgson

unread,
May 18, 2016, 7:53:13 AM5/18/16
to Jenkins Users
Ok, I tried creating two projects, one a freestyle job, the other a pipeline.

The only thing I set up in each was a file as parameter. I ran a  "Build using parameters" selecting the same file to upload.

When I tried to view the file in the freestyle job, it worked, but in the pipeline job I got the same error as above.

Brian Ray

unread,
May 18, 2016, 4:14:37 PM5/18/16
to Jenkins Users
Not 100% sure but I suspect that Pipeline job params can only be "regular" String parameters and perhaps param types whose values easily resolve to strings. My gut instinct is that more exotic param types that have side effects--like the File type--will not work.

So in the current use case the straightforward workaround would be to use a String parameter to specify a filesystem path or URI, and then have the Pipeline script place it in the workspace. There may be Pipeline-friendly plugins that could do this for you as well, though they are not coming to mind. (In our use cases all resources needed in the workspace come from checkout steps against a source repo and some custom scripting to grab binary artifacts from Artifactory.)

Jonathan Hodgson

unread,
May 18, 2016, 4:39:10 PM5/18/16
to Jenkins Users
Thanks,

What I've found so far also seems to indicate there is an issue with File Parameters in Pipeline plugins. If that's the case then it really begs the question as to why they're an option on the pipeline project setup page.

I'm having trouble seeing how I'm going to do what I need to do though, because the file has to be provided from a remote machine in the build call.. it's a diff file, I need to achieve a "try before commit".

As I said, I'm rather new to Jenkins.

Brian Ray

unread,
May 19, 2016, 1:24:11 AM5/19/16
to Jenkins Users
Aha. Pipeline's under heavy development so unfortunately, there are gaps like this.

How's the remote machine sharing the file? Windows directory share, e.g.?

Depending on the type of file and how it's shared will likely determine the strategy. I had no success getting a pipeline script to use the Groovy GDK URL#withReader API to slurp a file from a URL and plop it into the workspace with the writeFile step but that was several revisions back with Pipeline. Instead I do the same with a Groovy script executed via a sh/bat step, inside a node block. But that fit my use case.

Brian Ray

unread,
May 19, 2016, 1:25:47 AM5/19/16
to Jenkins Users
Sorry, the API was URL#withInputStream, not #withReader.

Jonathan Hodgson

unread,
May 19, 2016, 11:15:06 AM5/19/16
to Jenkins Users
The remote machine currently isn't sharing the file, that's part of the point of uploading it in the http POST, sorting out a share seems like it would be an issue, it needs to be dynamic.

Brian Ray

unread,
May 19, 2016, 6:30:40 PM5/19/16
to Jenkins Users
Gotcha, did not follow how you were getting it across to the build.

Jonathan Hodgson

unread,
May 19, 2016, 6:39:55 PM5/19/16
to Jenkins Users
The problem is, right now I'm not getting it to the build... but the idea is that the diff is generated locally and a build started by a local command line script, along the lines of this...

https://codeascraft.com/2011/10/11/did-you-try-it-before-you-committed/

It looks like one possibility is to escape the diff and then send it as a string parameter, is there a limit to the size one parameter can be, or is it just for the total POST?

Jonathan Hodgson

unread,
May 23, 2016, 11:24:35 AM5/23/16
to Jenkins Users
For the record, I got around this by using a string parameter.

It's a bit of a rigmarole, since I have to escape the diff to use it as a string parameter, and then write that string to a file before using it in Hg Patch (it may be possible to skip that step if I can work out how to pass it vias stdin without losing quotes), but it seems to work... at least for a small test diff.

On Thursday, May 19, 2016 at 7:39:55 PM UTC+1, Jonathan Hodgson wrote:
The problem is, right now I'm not getting it to the build... but the idea is that the diff is generated locally and a build started by a local command line script, along the lines of this...

https://codeascraft.com/2011/10/11/did-you-try-it-before-you-committed/

It looks like one possibility is to escape the diff and then send it as a string parameter, is there a limit to the size one parameter can be, or is it just for the total POST?


On Thursday, May 19, 2016 at 7:30:40 PM UTC+1, Brian Ray wrote:g

sivarajesh jarugula

unread,
Jun 8, 2016, 9:04:02 AM6/8/16
to Jenkins Users
Hi Jonathan,

I got a question related to your post.
I have a requirement to browse a directory (which is multiple files and sub directories) instead of a file (which is done by File parameter plugin).
I know with string parameter, I can ask user to give the path of the directory.  But this is error prone when he types or does the copy +paste of the directory path.
is there any way (or nay plugin) to have a browse button to take the directory instead of a file?

Thanks,
Siva Rajesh
Reply all
Reply to author
Forward
0 new messages