Downloading artifacts from Jenkins using wget or curl

Erik picture Erik · Jul 15, 2015 · Viewed 28.3k times · Source

I am trying to download an artifact from a Jenkins project using a DOS batch script. The reason that this is more than trivial is that my artifact is a ZIP file which includes the Jenkins build number in its name, hence I don't know the exact file name.

My current plan of attack is to use wget pointing at: /lastSuccessfulBuild/artifact/ to do some sort of recursive/mirror download.

If I do the following:

wget -r -np -l 1 -A zip --auth-no-challenge --http-user=**** --http-password=****  http://*.*.*.*:8080/job/MyProject/lastSuccessfulBuild/artifact/

(*s are chars I've changed for posting to SO)

I never get a ZIP file. If I omit the -A zip option, I do get the index.html, so I think the authorisation is working, unless it's some sort of session caching issue?

With -A zip I get as part of the response:

Removing ...+8080/job/MyProject/lastSuccessfulBuild/artifact/index.html since it should be rejected.

So I'm not sure if maybe it's removing that file and so not following its links? But doing -A zip,html doesn't work either.

I've tried several wget options, and also curl, but I am getting nowhere.

I don't know if I have the wrong wget options or whether there is something special about Jenkins authentication.

Answer

Slav picture Slav · Jul 15, 2015

You can add /*zip*/desired_archive_name.zip to any folder of the artifacts location.

If your ZIP file is the only artifact that the job archives, you can use:

http://*.*.*.*:8080/job/MyProject/lastSuccessfulBuild/artifact/*zip*/myfile.zip

where myfile.zip is just a name you assign to the downloadable archive, could be anything.

If you have multiple artifacts archived, you can either still get the ZIP file of all of them, and deal with individual ones on extraction. Or place the artifact that you want into a separate folder, and apply the /*zip*/ to that folder.