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:
\src\test\java\testdata\filename.xlsx
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
\src\test\java\testdata\abc.xlsx
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.
The Result
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.
That’s it!
Like this tutorial? Check out more tutorials on Jenkins.
What if I want to call my file name later on? Like if I send an email notification and want to include the file name in subject?
This should solve your problem. Please check:
http://dumbitdude.com/how-to-mail-reports-through-jenkins/
Are these steps still valid?
i tried following them but the file wasnt getting listed in the path I gave
I tried the above mentioned steps but im getting system cannot find the specified location error . How to provide the path in jenkins.can you please explain
The excel file is getting corrupted.
Is your excel file showing in the workspace? Mine doesn’t
Very helpful, thanx!
No problem 🙂
Sir, can you please provide what code you wrote in your java file to integrate it with jenkins?
Hi I am getting
HTTP ERROR 403 No valid crumb was included in the request
URI: /job/test2.0/build
STATUS: 403
MESSAGE: No valid crumb was included in the request
SERVLET: Stapler