Skip to content

Instantly share code, notes, and snippets.

Created May 23, 2023 07:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Bash script to print each job's duration for a given CircleCI workflow
# NOTE: This script requires:
# - curl
# - jq
# - your CircleCI API token (to be set via the $CIRCLE_TOKEN environment variable)
# Usage: sh ./ <workflow ID>
get_job_numbers_in_workflow () {
echo "For Workflow ID ${1}:"
curl -s -H "Circle-Token: $CIRCLE_TOKEN" \
"${1}/job" | jq '.items| map(select(.started_at != null)) | map({ p: .project_slug, j: .job_number|tostring}) | map(.|join("/job/"))' > "${1}.json"
print_duration_in_workflow () {
for path in $(jq -r ".[]" "${1}.json")
d=$(curl -s -H "Circle-Token: $CIRCLE_TOKEN" "${path}" | jq -r ".duration")
echo "\tjob ${path} took ${d} ms."
rm "${1}.json"
for w in "$@"
get_job_numbers_in_workflow $w
print_duration_in_workflow $w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment