Created
August 18, 2025 10:57
-
-
Save jprinet/e43cef7abda9c336ba11e1906fcdd6cf to your computer and use it in GitHub Desktop.
Count Develocity build scans
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
| #!/bin/bash | |
| # Parse CLI arguments | |
| if [[ $# -lt 3 ]]; then | |
| echo "Usage: $0 <develocity_url> <access_key> <from_instant_in_ms>" | |
| exit 1 | |
| fi | |
| # Init parameters | |
| readonly develocityUrl=$1 | |
| readonly apiKey=$2 | |
| readonly fromInstantInMs=$3 | |
| # Init global vars | |
| readonly maxBuildsPerBatch=1000 | |
| readonly recoveryFile="$0.recovery" | |
| readonly outputFile="$0.csv" | |
| buildScans="" | |
| buildCount=1 | |
| ############# | |
| # functions # | |
| ############# | |
| function getBuildScansByFilter() { | |
| local queryFilter=$1 | |
| buildScans=$(curl -s "${develocityUrl}/api/builds?${queryFilter}&maxBuilds=${maxBuildsPerBatch}" --header "authorization: Bearer ${apiKey}" | jq -r '.[].id') | |
| if [ "$?" != "0" ]; then | |
| echo "Failed to retrieve build scans" | |
| exit 1 | |
| fi | |
| } | |
| function getBuildScansFromInstant() { | |
| local instant=$1 | |
| echo "Fetching builds fromInstant=${instant} => $(date -d @$(echo ${fromInstantInMs} | head -c 10))" | |
| getBuildScansByFilter "fromInstant=${instant}" | |
| } | |
| function getBuildScansFromBuildId() { | |
| local buildId=$1 | |
| echo "" | |
| echo "Fetching builds fromBuild=${buildId}" | |
| getBuildScansByFilter "fromBuild=${buildId}" | |
| } | |
| ######## | |
| # main # | |
| ######## | |
| # check if recovery data are present | |
| recoveryBuildScanId=$(cat "${recoveryFile}" 2>/dev/null) | |
| if [[ -z "${recoveryBuildScanId}" ]] | |
| then | |
| # Clean output files | |
| rm -f ${outputFile} | |
| rm -f ${workFile} | |
| # Get first batch of builds | |
| getBuildScansFromInstant ${fromInstantInMs} | |
| else | |
| echo "Recovering data from build scan id ${recoveryBuildScanId} (you can trigger a fresh run by deleting ${recoveryFile})" | |
| # Get first batch of builds | |
| getBuildScansFromBuildId ${recoveryBuildScanId} | |
| fi | |
| totalBuildCount=0 | |
| # Iterate over build scan list | |
| while [ ! -z "${buildScans}" ] | |
| do | |
| buildScanId="" | |
| IFS=$'\n' | |
| for buildScan in ${buildScans}; do | |
| echo -ne "*" | |
| # Parse field | |
| buildScanId=$(echo "${buildScan}" | cut -d, -f 1) | |
| # save build scan id for recovery mode | |
| echo "${buildScanId}" > ${recoveryFile} | |
| totalBuildCount=$((totalBuildCount+1)) | |
| done | |
| getBuildScansFromBuildId ${buildScanId} | |
| done | |
| # Remove recovery data | |
| rm -f ${recoveryFile} | |
| # Display results | |
| echo "Build scans count: ${totalBuildCount}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment