Created
July 25, 2025 12:20
-
-
Save axi92/354c5733a8e7c492383d89cc42f77470 to your computer and use it in GitHub Desktop.
Bamboo build times over a period
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # === CONFIGURATION === | |
| BAMBOO_URL="https://bamboo.domain.com/" | |
| USERNAME="" | |
| PASSWORD="" | |
| MAX_RESULTS=100 # Increase if needed | |
| # === DATE RANGE === | |
| NOW=$(date +%s) | |
| DAYS=90 | |
| DAYS_AGO=$((NOW - DAYS * 24 * 60 * 60)) | |
| # === GET ALL PLAN KEYS === | |
| plan_keys=$(curl -s -u "$USERNAME:$PASSWORD" \ | |
| "$BAMBOO_URL/rest/api/latest/plan.json?expand=plans.plan&max-results=1000" | | |
| jq -r '.plans.plan[].key') | |
| total_duration=0 | |
| # === ITERATE OVER PLANS === | |
| for PLAN_KEY in $plan_keys; do | |
| echo "🔍 Checking builds for plan: $PLAN_KEY" | |
| result=$(curl -s -u "$USERNAME:$PASSWORD" \ | |
| "$BAMBOO_URL/rest/api/latest/result/${PLAN_KEY}.json?expand=results.result&max-results=$MAX_RESULTS") | |
| while IFS=$'\t' read -r buildNumber date durationMin; do | |
| echo " - Build #$buildNumber on $date — Duration: ${durationMin} min" | |
| total_duration=$((total_duration + durationMin)) | |
| echo " ↪️ Sum for now: ${total_duration} min" | |
| done < <( | |
| echo "$result" | jq -r --argjson DAYS_AGO "$DAYS_AGO" ' | |
| .results.result[]? | | |
| select( | |
| (.buildCompletedDate // null) != null and | |
| (.buildCompletedDate | type == "string") and | |
| (.buildCompletedDate | test("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}")) | |
| ) | | |
| { | |
| number: .buildNumber, | |
| date: .buildCompletedDate, | |
| epoch: ( | |
| .buildCompletedDate | |
| | capture("(?<date>\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})") | |
| | .date | |
| | strptime("%Y-%m-%dT%H:%M:%S") | |
| | mktime | |
| ), | |
| duration: ((.buildDurationInSeconds // 0) / 60) | |
| } | | |
| select(.epoch >= $DAYS_AGO) | | |
| "\(.number)\t\(.date)\t\(.duration | round)" | |
| ' | |
| ) | |
| done | |
| echo "" | |
| echo "🧮 Total build time across all plans (last $DAYS days): $total_duration minutes" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment