Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload a generic file into a Jenkins job?

I am trying to find a way to prompt the user to select and upload a generic file from a local machine to a Jenkins job prior to build. The input file that user is going to upload is not necessarily a text or a property file.

I am specifically trying to get the user to "select" their desired file - browse to their file ; the user should not pass the file's path.

Thanks

like image 559
DAZA Avatar asked Dec 15 '14 19:12

DAZA


3 Answers

Use the File Parameter:

File parameter allows a build to accept a file, to be submitted by the user when scheduling a new build. The file will be placed inside the workspace at the known location after the check-out/update is done, so that your build scripts can use this file.

enter image description here

If you need to verify the file has a certain extension, you would have to do that with a script as part of your job, and fail the job is extension/content-type does not match what you need.

like image 59
Slav Avatar answered Oct 26 '22 03:10

Slav


This is kind of annoying to handle when you don't know what the file name will be or need to change its name before it reaches its destination. You kind of need to perform a hack. This is how I do it:

  1. Use the "File parameter" parameter to upload your file
  2. Use the OS-specific script to rename the file from whatever you named your File Parameter to whatever you want it to be, e.g., if my File Parameter had the File location value of file_name instead of an actual relative file-path, I'd then do something like this for say, Windows inside a Build-Step for "Execute Windows Batch Command":

move .\file_name .\%file_name%

And then just use ArtifactDeployer to copy everything there to your desired location.

ps: this won't remove digital signatures, so the move-operation should be considered mostly safe.

like image 4
kayleeFrye_onDeck Avatar answered Oct 26 '22 03:10

kayleeFrye_onDeck


The use of the Jenkins File Parameter will not work for Jenkins pipelines. It's ridiculous that they don't disable that kind of build parameter for pipelines. It's even more ridiculous that they don't at the very least, identify this SEVERE limitation in the help documentation for that parameter.

It would have saved me a couple hours trying to figure out why it would not work in my pipeline.

Refer to this feature request for more details: https://issues.jenkins-ci.org/browse/JENKINS-27413

like image 3
John Czukkermann Avatar answered Oct 26 '22 04:10

John Czukkermann