How to use FileParameterValue in jenkins 2 pipe

As a file from the current workspace of the project is transferred as a parameter to another project.

eg. sort of:

build job: 'otherproject', parameters: [[$class: 'FileParameterValue', name: 'output.tar.gz', value: ??? ]], wait: false 
+6
source share
3 answers

I tried it myself recently with little success. This seems to be the problem. According to the documentation for the FileParameterValue class, there is a constructor that accepts java.io.File like this:

 @DataBoundConstructor FileParameterValue(String name, org.apache.commons.fileupload.FileItem file) 

There is another one waiting for a FileItem , for example:

 FileParameterValue(String name, File file, String originalFileName) 

But since only the first is annotated using @DataBoundConstructor , even when I try to use the latter in a script:

 file = new File(pwd(), 'test.txt'); build( job: 'jobB', parameters: [ [$class: "FileParameterValue", name: "TEST_FILE", file: file, originalFileName: 'test.txt'] ] ) 

Note that this requires a script statement to instantiate java.io.File

... I get the following error:

 java.lang.ClassCastException: hudson.model.FileParameterValue.file expects interface org.apache.commons.fileupload.FileItem but received class java.io.File 

I understand that only a file uploaded by the user as an interactive login at runtime provides an object of type org.apache.commons.fileupload.FileItem , so in the end I resorted to archiving the file in the first task and unarchiving in the transition work and solve the problem . Of course, this is not ideal, but if you are in traffic, this is the fastest way to figure it out.

0
source

You can not. Here is the bug Zhukinsky. Update this topic after fixing the error. In the meantime, log in and vote on this issue and ask them to add documentation for the pipeline assembly job parameters.

https://issues.jenkins-ci.org/browse/JENKINS-27413

Link here: http://jenkins-ci.361315.n4.nabble.com/pipeline-build-job-with-FileParameterValue-td4861199.html

Here is the documentation for the different types of parameters (link to FileParameterValue)

http://javadoc.jenkins.io/hudson/model/FileParameterValue.html

0
source

Try passing the FileParameterValue instance to the parameters (it worked for me):

 import hudson.model.* def param_file = new File("path/to/file") build job: 'otherproject', parameters: [new FileParameterValue('file_param_name', param_file, 'original_file_name')], wait: false 
0
source

All Articles