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