Skip to content

Instantly share code, notes, and snippets.

@tomdwp
Created June 22, 2018 23:14
Show Gist options
  • Save tomdwp/aedee726780b709be9b0f5526d58bb4e to your computer and use it in GitHub Desktop.
Save tomdwp/aedee726780b709be9b0f5526d58bb4e to your computer and use it in GitHub Desktop.
This is a bash script to download the artifacts from a Circle CI job. You will need to configure with your Circle CI API token, the github account related to the Circle CI job, and the github project name.
#!/bin/bash
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 2 ] || die "::\tThis script downloads the output files from a Circle CI job\t::\n::\tpass the Circle CI job number as first argument\t\t\t::\n::\tpass the output folder as second argument\t::"
echo $1 | grep -E -q '^[0-9]+$' || die "::\tCircle CI build number required, [ $1 ] provided\t\t::"
if [ -d "$2" ]; then
echo " "
else
die "::\tCircle CI output folder provided does not exist! script cannot proceed!! [ $2 ] provided\t\t::"
fi
CIRCLECI_JOB_NUMBER=$1 #see Circle CI web interface to get job number
OUTPUT_DIR=$2
# use the CircleCI web interface to generate an API key
CIRCLE_TOKEN='REPLACE_WITH_YOUR_CIRCLE_CI_API_KEY'
GITHUB_ACCOUNT_NAME='REPLACE_WITH_THE_GITHUB_ACCOUNT_NAME_FOR_YOUR_GITHUB_PROJECT'
GITHUB_REPO_NAME='REPLACE_WITH_YOUR_GITHUB_REPO_NAME'
pushd $OUTPUT_DIR >/dev/null 2>&1
curl https://circleci.com/api/v1.1/project/github/$GITHUB_ACCOUNT_NAME/$GITHUB_REPO_NAME/$CIRCLECI_JOB_NUMBER/artifacts?circle-token=$CIRCLE_TOKEN | grep -o 'https://[^"]*' > circleci_artifacts_for_job_$CIRCLECI_JOB_NUMBER.txt
<circleci_artifacts_for_job_$CIRCLECI_JOB_NUMBER.txt xargs -P4 -I % wget %?circle-token=$CIRCLE_TOKEN
# wget leaves the querystring at the end of each file downloaded
# need to strip that off
for i in `find . -type f`
do
mv $i `echo $i | cut -d? -f1`
done
popd >/dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment