問題
artifact が大量にあるので、1個づつダウンロードするのが面倒くさい。
一気にダウンロードしたい。
スクリプト
以下のスクリプトを実行するには Personal API Tokens page で作成したトークンを環境変数 CIRCLECI_TOKEN
に格納しておく必要がある。
download_artifacts.sh
# !/bin/bash
if [ "$1" = "" ]; then
echo "usage: $0 job_number"
exit 1
fi
project_slug=gh/{your-name}/{repo} # ここを自分のリポジトリに合わせて変更する
job_number=$1
work_dir="results/${job_number}"
mkdir -p "${work_dir}"
curl --silent \
-X GET "https://circleci.com/api/v2/project/${project_slug}/${job_number}/artifacts" \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header "Circle-Token: $CIRCLECI_TOKEN" \
| grep -o 'https://[^"]*' \
| grep 'xml' \
| xargs -P4 -I % wget --header="Circle-Token: $CIRCLECI_TOKEN" --directory-prefix "$work_dir" %
実行時にパラメタとして job number を渡す
$ sh download_artifacts.sh 99041
ダウンロードした結果は results/
配下に格納される。
$ tree results
results
└── 99041
├── rspec.xml
├── rspec.xml.1
├── rspec.xml.10
├── rspec.xml.11
├── rspec.xml.12
├── rspec.xml.13
├── rspec.xml.14
├── rspec.xml.15
├── rspec.xml.2
├── rspec.xml.3
├── rspec.xml.4
├── rspec.xml.5
├── rspec.xml.6
├── rspec.xml.7
├── rspec.xml.8
├── rspec.xml.9