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.

meme for jenkins

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.

click on configure in jenkins

Step 2: In Maven Info Plugin Configuration click on the checkbox that reads “This project is parameterized”

check the parameter checkbox

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.

file parameter option in dropdown

 

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.

save parameter entering file location

 

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.

click on save button

The Result

Step 6: Time to build it. Click on Build with Parameters.

build with parameters option in Jenkins

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.

click to upload a file in jenkins

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.

location of your file

Step 9: If you are ready to run your build just go ahead and do that.

build button in jenkins

 

That’s it!

Like this tutorial? Check out more tutorials on Jenkins.

Scottshak

Poet. Author. Blogger. Screenwriter. Director. Editor. Software Engineer. Author of "Songs of a Ruin" and proud owner of four websites and two production houses. Also, one of the geekiest Test Automation Engineers based in Ahmedabad.

You may also like...

11 Responses

  1. P Pual says:

    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?

  2. kota says:

    Are these steps still valid?
    i tried following them but the file wasnt getting listed in the path I gave

  3. raji says:

    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

  4. Faiz says:

    The excel file is getting corrupted.

  5. sony says:

    Very helpful, thanx!

  6. Prem kumar says:

    Sir, can you please provide what code you wrote in your java file to integrate it with jenkins?

  7. Ayesha says:

    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

Leave a Reply