Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Created May 23, 2024 03:33
Show Gist options
  • Save magnetikonline/61ba71203a0f0587e416df74664a0ddf to your computer and use it in GitHub Desktop.
Save magnetikonline/61ba71203a0f0587e416df74664a0ddf to your computer and use it in GitHub Desktop.
Delete all AWS CodeBuild build history.

Delete all AWS CodeBuild build history

Quick way to delete all existing build history from AWS CodeBuild using the AWS CLI.

#!/bin/bash -e

buffer=()
for buildId in $(aws codebuild list-builds --query 'ids.join(`\n`,@)' --output text); do
  buffer+=($buildId)
  if [[ ${#buffer[@]} -ge 100 ]]; then
    aws --no-cli-pager codebuild batch-delete-builds --ids "${buffer[@]}"
    buffer=()
  fi
done

if [[ ${#buffer[@]} -gt 0 ]]; then
  aws --no-cli-pager codebuild batch-delete-builds --ids "${buffer[@]}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment