Skip to content

Instantly share code, notes, and snippets.

@pestilence669
Created February 4, 2019 23:27
Show Gist options
  • Save pestilence669/d29ec9dd591d583e081bafd262594c65 to your computer and use it in GitHub Desktop.
Save pestilence669/d29ec9dd591d583e081bafd262594c65 to your computer and use it in GitHub Desktop.
Delete old deployed versions on Google App Engine
#!/bin/bash
# vim: set ts=4 sw=4 noet fileencoding=utf-8:
readonly SERVICE=${1-api}
readonly versions=$(gcloud app versions list --service=$SERVICE \
--sort-by=~version.createTime \
--format='table[no-heading](id)')
declare -i KEEP_LAST=${KEEP_LAST-5}
declare -i c=0
for version in $versions; do
((++c))
if [[ $c -gt $KEEP_LAST ]]; then
gcloud versions delete --service $SERVICE --version $version
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment