How to Upload a File in Jenkins | Using File Parameter
Learn how to upload a file in Jenkins using file parameter. At times you might be required to add a field in your build with the help of which your end user or client could easily upload a file. So the parameter is basically a file to be uploaded at runtime. How do you do that?
There is this field called file parameter provided by Jenkins that lets you do that. I have made a short tutorial on how to upload a file in Jenkins using file parameter that will assist you in achieving that.
Check it out:
How to Upload a File in Jenkins
So let’s say you have an ongoing project that you wish to add a file parameter field to.
Step 1: Click on the Configure button to open the configuration page.
Step 2: In Maven Info Plugin Configuration click on the checkbox that reads “This project is parameterized”
Doing so will show the Add Parameter dropdown.
Step 3: Click on the Add Parameter drop-down to reveal all the available parameter options. Then click on File Parameter.
On clicking File Parameter, a small box of File Parameter will open.
Understanding File Parameter Field
So what basically file parameter does is that it creates an upload box from where you can select your file. It uploads the file to the base location (workspace). If you want the file to be uploaded to some specific location in your workspace you can provide that location like this:
where filename.xlsx is your file name and extension.
Step 4: In the file location field, enter the location where you want your file to be uploaded to.
I have put the location as
where abc.xlsx is my file name. In my code, I have provided the same path to be read from.
You can provide the description as well if you want or instructions for your fellow end users or clients to run the build.
Step 5: Click on Save once done.
Step 6: Time to build it. Click on Build with Parameters.
You will notice a new input parameter now created with the option to upload a file.
Step 7: To see things in action, click on Choose File.
It will open a dialog box.
Step 8: Select the file you want to upload. In my case, it was abc.xlsx located on my desktop. I am gonna go ahead and select that and then click on open.
Step 9: If you are ready to run your build just go ahead and do that.
Like this tutorial? Check out more tutorials on Jenkins.