Skip to content
Latchkey

gcloud functions deploy: Deploy Cloud Functions in CI

Deploy a Cloud Function (Gen 1 or Gen 2) from source with a runtime and trigger.

gcloud functions deploy packages your source and deploys it as a Cloud Function. You specify the runtime, the entry point, and a trigger (HTTP or event). In CI you run it after tests pass to ship the new code.

Common flags

  • NAME - the function name (positional)
  • --runtime=nodejs20 - language runtime
  • --trigger-http or --trigger-topic=TOPIC - how the function is invoked
  • --entry-point=fn - exported function to run
  • --region=REGION and --gen2 - placement and generation

Example in CI

Deploy an HTTP-triggered Gen 2 function from the repo root.

shell
gcloud functions deploy api \
  --gen2 --runtime=nodejs20 --region=us-central1 \
  --trigger-http --entry-point=handler \
  --source=. --quiet

Common errors in CI

  • Build failed: ... function not found - wrong --entry-point name
  • OperationError: ... PERMISSION_DENIED - SA missing roles/cloudfunctions.developer
  • Cloud Functions API has not been used ... before or it is disabled - enable cloudfunctions.googleapis.com

Key takeaways

  • Deploys a function from source with an explicit runtime, entry point, and trigger.
  • Use --gen2 for the modern Cloud Run-backed functions platform.
  • Entry-point and IAM-role mismatches are the most common CI failures.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →