Develop an plugin to save uploaded file.

34 views
Skip to first unread message

icetree521

unread,
May 2, 2016, 8:16:14 AM5/2/16
to Jenkins Developers
Hi,
I am new to plugin developing and got stucked now. 

Suppose user  trigger a build with and file parameter. 

curl -vvv -X POST http://127.0.0.1:8080/jenkins/job/t/build \
 
--form file0='@/tmp/foo.xml' \
 
--form json='{"parameter": [{"name":"XML_PATH", "file":"file0"}]}'


In plugin, how can we save this foo.xml into job's workspace ?

Does anybody has experience on this ? 

I would like to extended BuildWrapper and rewrite the setUp method, but the req and formData are null. How can I get these two vars inside BuildWrapper ?

FileParameterDefinition fd = new FileParameterDefinition("init_name", "my description");
fd
.createValue(StaplerRequest req, JSONObject formData);


icetree521

unread,
May 2, 2016, 8:36:05 AM5/2/16
to Jenkins Developers
   I also tried getCurrentRequest but with no luck, the req is still null, anybody can provide my some guidance ? Many appreciates in advance.

   FileParameterDefinition fd = new FileParameterDefinition("init_name", "my description");

   
StaplerRequest req=Stapler.getCurrentRequest();
   fd
.createValue(req);



Daniel Beck

unread,
May 2, 2016, 8:39:32 AM5/2/16
to jenkin...@googlegroups.com

> On 02.05.2016, at 14:16, icetree521 <icetr...@gmail.com> wrote:
>
> In plugin, how can we save this foo.xml into job's workspace ?
>

If that's a regular (freestyle) project, and a regular file parameter, the file is already in the workspace.

icetree521

unread,
May 2, 2016, 8:52:43 AM5/2/16
to Jenkins Developers, m...@beckweb.net
Nope.  If I predefined a file parameter from job config page then the file can successfully uploaded into the workspace. 

But in my case,  I didn't predefined and file parameter from the job config page. What I want is to set the file parameter programmatically (by plugin). 

Currently the parameter can be created but the content is empty. which means the plugin not successfully received the file content from the user post form.
Reply all
Reply to author
Forward
0 new messages