Sometimes it’s useful to get all the artifact files for a build. Here’s how you can do that with 3 lines of bash and no dependencies. This works with both CircleCI 1.0 and 2.0.
First create an API token via our UI: Go to ‘Account Settings > API Tokens’, create a new token and copy it.
CD
to a directory where you would like the artifacts files to be. Then run:
export CIRCLE_TOKEN='?circle-token=:your_token'
curl https://circleci.com/api/v1.1/project/:vcs-type/:username/:project/:build_num/artifacts$CIRCLE_TOKEN | grep -o 'https://[^"]*' > artifacts.txt
<artifacts.txt xargs -P4 -I % wget %$CIRCLE_TOKEN
Note 1: Replace all the variables above that start with a :
with real values for your project (don’t include the colon).
Note 2: :vcs-type
will be github
or bitbucket
.
Note 3: The xargs
command runs 4 processes to download files in parallel. You can adjust this value to your needs.
Explanation: The line beginning curl
fetches all the artifacts details for a build - we then pipe this through the grep
command to extract just the URLs. The results are saved to a file artifacts.txt
. Then xargs
reads in that file and downloads each artifact file.