Rollback your Google Cloud Function to its previous version

Photo by Testalize.me on Unsplash
FUNCTION_NAME="place-your-function-name-here"
PROJECT_ID="place-your-project-id-here"
PROJECT_NUM=$(gcloud projects describe $PROJECT_ID \
--format="value(project_number)")
VERSION_NUM=$(gcloud functions describe --project=leoy-toolbox \
$FUNCTION_NAME --format="value(version_id)")
BUILD_NUM=$(gcloud functions describe --project=leoy-toolbox \
$FUNCTION_NAME --format="value(build_id)")
LOCATION=$(gcloud functions describe --project=leoy-toolbox \
$FUNCTION_NAME --format="value(name)") | awk -F/ '{ print $4 }')
SOURCE=$(gsutil --p=$PROJECT_ID ls \
gs://gcf-sources-$PROJECT_NUM-$LOCATION/$FUNCTION_NAME* \
| grep -v "version-$VERSION_NUM" | tail -1)
gcloud functions deploy --project=$PROJECT_ID $FUNCTION_NAME \
--source=$SOURCE/function-source.zip \
--region=$LOCATION

--

--

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
minherz

DevRel Engineer in Google Cloud, specializing in Observability and Reliability. I try to whisper to horses in free time.