jenkinsci / file-parameters-plugin

https://plugins.jenkins.io/file-parameters/
MIT License
14 stars 11 forks source link

Use of a stashedFile parameter in a build step #126

Open RobinFauvel opened 2 years ago

RobinFauvel commented 2 years ago

Describe your use-case which is not covered by existing documentation.

The documentation clearly indicates how to pass a base64File parameter to a downstream Job via the build step. This is not the case for a parameter of type stashedFile. In particular, how to create a file of type org.apache.commons.fileupload.FileItem to give to the file argument? Thank you

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

No response

jglick commented 2 years ago

I do not think there should be any difference. base64File and stashedFile would differ only in how the downstream build stores the parameter, not how it accepts it.

jamesvanhorn commented 1 year ago

Is there any update here? I am facing the same issue. I have a job that takes a stashedFile and a string as parameters, but I can't figure out how to call that from an upstream pipeline?

File build = runSomeOtherMethod();
build job: 'build-server-apk', parameters: [
                            stashedFile(name: 'FILE', base64: Base64.encoder.encodeToString(build.bytes)),
                            string(name: 'BUILD_CONFIG', value: "${buildConfig}")
                    ]

This results in an error like...

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.io.File.call() is applicable for argument types: (java.util.LinkedHashMap) values:  [[job:build-server-apk, parameters:[@stashedFile(name=FILE,value=/jenkins_data/jenkins_home/jobs/TWC Flagship App/jobs/Apps-Upload-Build-To-BrowserStack-With-Espresso/workspace/sdui-main-104.apk), ...]]]
Possible solutions: wait(), any(), wait(long), any(groovy.lang.Closure), each(groovy.lang.Closure), list()

To be clear this is a larger file, hence the use of a stashed file. about 150MB

Edit: that output was actually from a second run passing the java.nio.File object directly. Encoding to Base64 string did not work either for reference.

jglick commented 1 year ago

Is there any update here?

Sorry, no, I have not found time to write a test for this scenario and investigate.

this is a larger file, hence the use of a stashed file. about 150MB

FYI performance is likely to be poor if you are trying to pass around large files between builds using the build step. https://github.com/jenkinsci/file-parameters-plugin#usage-with-build is intended for small files only (for which stashing would be overkill anyway). Efficiently transferring large files would require a more complicated design TBD. It is best to handle large files using an external artifact repository or blob store and have Jenkins just pass around URLs or other handles, though I suppose if you had such a system configured and available you would not need this plugin to begin with!

jamesvanhorn commented 1 year ago

Thank you, appreciate the response. Yeah I wish I had an artifact repo setup for this haha. Though your phrasing does give me an alternative idea that may be workable. We do a fetch on the file in the parent pipeline. My thought was to pass the file along, but that's how I ended up here....

It's not ideal, but I could just pass the name of the file into the child job and rerun the fetch a second time. Not the end of the world I suppose.

jglick commented 1 year ago

If you can fetch the file from somewhere else, that is probably better, as it reduces the disk consumption and I/O pressure on the Jenkins controller (assuming you run builds on agents). Stashed file parameters are more intended for cases where largish files must be submitted to the controller, whether through a browser upload by a human, or REST or CLI action from some external tool, and would not easily be available for download.