Skip to content

Menu

gcloud CLI Cheat Sheet: Auth, Configurations, Cloud Run, Logging, --format and --filter

Checked against Google Cloud CLI (gcloud) Google Cloud CLI 594.0.1 (21 Nov 2026) on 28 November 2026. Each section links to the official docs it was checked against.

This sheet is for developers who use gcloud for day-to-day Google Cloud work rather than for one-off setup. It tracks the gcloud reference and release notes as of 28 Nov 2026, when the latest release was 594.0.1. gcloud is not installed in my test shell, so the rows come from the reference pages and are marked untested.

When to use what

Keep two kinds of credentials straight. gcloud auth login signs in the CLI itself. gcloud auth application-default login writes Application Default Credentials for your code and client libraries, and its reference says it does not touch the accounts gcloud uses. Most "works in the terminal, fails in my app" problems come from having one and not the other.

Use named configurations instead of running gcloud config set project back and forth. Make one per project or account, then switch with activate, or pass --configuration for a single command. In scripts, set CLOUDSDK_ACTIVE_CONFIG_NAME so the script cannot inherit whatever you last activated by hand.

For output, --format is the tool you want in scripts: value(...) gives bare values for shell variables, csv(...) and json feed other tools, and table(...) with box and sort is for reading. Pair it with --filter to cut rows; logic words must be uppercase and mixed AND/OR needs parentheses.

For Cloud Run, --update-env-vars is usually what you mean; --set-env-vars replaces the full set. If an AI agent will run these commands, see the GCP MCP server and the Cloud Run MCP server, plus our post on MCP servers for cloud infrastructure. The YAML validator helps with service YAML before you deploy it.

gcloud auth login

Browser sign-in for your user account; sets it active in the current configuration

From the docs, not run by us
gcloud auth login --no-launch-browser

Print a URL to open elsewhere and paste the code back

From the docs, not run by us
gcloud auth login --update-adc

Also write the credentials to the Application Default Credentials location

From the docs, not run by us
gcloud auth application-default login

Create ADC for local code and client libraries; does not change gcloud's own accounts

Source: https://docs.cloud.google.com/sdk/gcloud/reference/auth/application-default/login

From the docs, not run by us
gcloud auth list

Show which accounts have credentials and which is active

From the docs, not run by us

You can't delete the active configuration; activate another one first.

gcloud config configurations create staging

Create a named configuration; activate it before use

From the docs, not run by us
gcloud config configurations activate staging

Switch every following command to that configuration

From the docs, not run by us
gcloud config configurations list

List configurations and see which one is active

From the docs, not run by us
gcloud config set project my-project

Set the default project in the active configuration

From the docs, not run by us
gcloud config set compute/region us-central1

Set the default region for compute commands

From the docs, not run by us
gcloud config list

Print the active configuration's properties

From the docs, not run by us
gcloud auth list --configuration=staging

Use another configuration for one command only

From the docs, not run by us
export CLOUDSDK_ACTIVE_CONFIG_NAME=staging

Pin a configuration for the whole shell session or script

From the docs, not run by us
gcloud projects list --sort-by=projectId --limit=5

First five projects sorted by ID

Source: https://docs.cloud.google.com/sdk/gcloud/reference/projects/list

From the docs, not run by us
gcloud projects list --filter='lifecycleState:DELETE_REQUESTED'

Projects pending deletion

Source: https://docs.cloud.google.com/sdk/gcloud/reference/projects/list

From the docs, not run by us
gcloud compute instances list

All VMs in the project as a table

From the docs, not run by us
gcloud compute instances list --zones=us-central1-a

Only VMs in the given zones

From the docs, not run by us
gcloud compute instances list --uri

Print each VM's resource URI instead of a table

From the docs, not run by us
gcloud compute ssh example-instance --zone=us-central1-a

SSH to a VM; gcloud handles keys and resolves the address

Source: https://docs.cloud.google.com/sdk/gcloud/reference/compute/ssh

From the docs, not run by us
gcloud compute ssh example-instance --zone=us-central1-a --tunnel-through-iap

Connect through Identity-Aware Proxy instead of a public IP; not combinable with --internal-ip

Source: https://docs.cloud.google.com/sdk/gcloud/reference/compute/ssh

From the docs, not run by us
gcloud run deploy my-backend --image=us-docker.pkg.dev/project/image

Deploy a prebuilt image to a service

From the docs, not run by us
gcloud run deploy my-backend --source .

Build from the local folder and deploy

From the docs, not run by us
--region=us-central1

Region the service runs in

From the docs, not run by us
--allow-unauthenticated

Allow public access; --no-allow-unauthenticated turns it off

From the docs, not run by us
--update-env-vars=KEY=VALUE

Add or change variables and keep the rest

From the docs, not run by us
--set-env-vars=KEY=VALUE

Replace the entire set of environment variables

From the docs, not run by us
--set-secrets=DB_PASS=db-pass:latest

Map secrets to env vars; values use NAME:VERSION

From the docs, not run by us
--no-traffic --tag=canary

Deploy a revision that gets no traffic, reachable by its tag

From the docs, not run by us
--min-instances=1 --max-instances=10

Per-revision instance bounds; --min sets a service-wide minimum

From the docs, not run by us

Filter operators: =, !=, : (pattern), ~ and !~ (regex), < <= >= >, and uppercase NOT, AND, OR. Source: https://docs.cloud.google.com/sdk/gcloud/reference/topic/filters

gcloud logging read "severity>=ERROR" --limit=10

Newest error entries first; default window is the last day (--freshness=1d)

Source: https://docs.cloud.google.com/sdk/gcloud/reference/logging/read

From the docs, not run by us
gcloud logging read "resource.type=gce_instance" --format=json

Full log entries as JSON for jq or a file

Source: https://docs.cloud.google.com/sdk/gcloud/reference/logging/read

From the docs, not run by us
--format="value(config.account)"

Print a bare value, handy for shell variables

From the docs, not run by us
--format="table[box,title=Instances](name:sort=1, zone:label=zone, status)"

Boxed table with a title, sorted by name, with a relabelled column

From the docs, not run by us
--format="csv(quotas.metric,quotas.limit,quotas.usage)"

CSV of nested fields

From the docs, not run by us
--filter="zone ~ us AND -machineType:f1-micro"

Regex match on zone and exclude a machine type

Source: https://docs.cloud.google.com/sdk/gcloud/reference/topic/filters

From the docs, not run by us
--filter="labels.my-label:*"

Rows where the label exists at all

Source: https://docs.cloud.google.com/sdk/gcloud/reference/topic/filters

From the docs, not run by us

Worked example: Ship a Cloud Run revision as a canary, then check its errors

You want a new build live under a tag without moving user traffic, using a dedicated staging configuration so nothing lands in production by accident.

gcloud config configurations create staging
gcloud config configurations activate staging
gcloud config set project my-staging-project

gcloud run deploy my-backend \
  --image=us-docker.pkg.dev/project/image \
  --region=us-central1 \
  --update-env-vars=FEATURE_X=on \
  --no-traffic --tag=canary

gcloud logging read "severity>=ERROR" --limit=10 --format=json

I couldn't run gcloud here, so this is what to expect rather than real output. After the deploy, gcloud reports the new revision and a URL for the canary tag; the main service URL still serves the previous revision because of --no-traffic. --update-env-vars adds FEATURE_X and leaves the existing variables alone, which --set-env-vars would not.

The last command prints up to ten error entries from the past day, newest first. Narrow it to this service by adding a resource filter (the logging read page shows the resource.type=... form), then check the entries mention the new revision name. If the list is empty, that is the result you wanted.

Common mistakes

  • Running gcloud auth login and expecting your Python or Node code to pick up the same credentials.

    Client libraries read Application Default Credentials. Run gcloud auth application-default login, or use --update-adc on login.

  • Using --set-env-vars to change one variable on a running Cloud Run service.

    It replaces every variable. Use --update-env-vars for a single change.

  • Writing filters with lowercase and or mixing AND and OR without parentheses.

    The filters topic requires uppercase logic words and parentheses when AND and OR are combined.

  • Switching projects with gcloud config set project in a shared shell script.

    Use a named configuration and set CLOUDSDK_ACTIVE_CONFIG_NAME or pass --configuration so the script is explicit.

  • Parsing the default table output in scripts.

    Use --format=json or --format="value(field)"; table layout is for people and can change.