How to have a Jenkins build step that downloads a URL?

I'd like to have a Jenkins build step which just downloads a given URL into the workspace. Is there a simple way to do that?

(I currently use an Ant script which does a simple <get/>. But that means I need to have that script in SVN somewhere, and check it out during the build. I find that cumbersome.)

Update: To clarify, I'd like to download a URL without installing additional software on the build system or using an additional script. (A Jenkins plugin is fine, of course.) Preferably I don't want to depend on the build slave being Linux, Windows, or whatever.

Upvotes: 19

Views: 51645

Answers (5)

Mikhail
Mikhail

Reputation: 1303

In case you don't want to meddle with installing plugins or running shell commands (e.g. there might be no curl on windows), you may do this programmatically:

file_text = new URL ("https://some.site.com/some_file.html").getText()
writeFile(file: 'file.html', text: file_text)

To run this you will need to make some in-process script approvals as usual with custom code in Jenkins.

In cause you need to configure actual request, check this for getText() parameters.

Based on this gist and this answer

Upvotes: 9

Sergii Zhuravskyi
Sergii Zhuravskyi

Reputation: 4348

How Download file with Jenkins HTTP Request Plugin. How to download file into Jenkins workspace. I was downloading a tar.gz file from our Nexus (Artifactory) which is a local repository into work-space of a Jenkins build steps. Steps to be done:

  1. Add build step "Http Request", obviously you need to have https://wiki.jenkins-ci.org/display/JENKINS/HTTP+Request+Plugin .
  2. Specify your URL and HTTP method.
  3. Open "Advanced.." configuration. (Click it)
  4. Go to Response section.
  5. Use "Output Response to file" field to specify name and extension of your file
  6. Please use this screenshot for details
  7. after download you can find desired file inside your workspace with name that you specified in step# 5.

Upvotes: 12

AnneTheAgile
AnneTheAgile

Reputation: 10240

This plugin works great to do a get/put/post/delete on any REST type url: HTTP Request Plugin - on the Jenkins Wiki ; https://wiki.jenkins-ci.org/display/JENKINS/HTTP+Request+Plugin

Upvotes: 0

gareth_bowles
gareth_bowles

Reputation: 21130

The simplest way is just to have a shell script build step that does a wget or curl on your URL. But the plugins that @Bernard suggests will probably give you additional functionality.

Upvotes: 6

Bernard
Bernard

Reputation: 7961

Have you looked at the URL SCM plugin? It seems like it has the functionality you are looking for. There are also other URL-based plugins available for Jenkins that you can explore.

Upvotes: 5

Related Questions