Skip to content
Latchkey

gcloud functions deploy: Gen2, Triggers & CI Errors

Deploy a Cloud Function with its runtime, trigger, and entry point.

gcloud functions deploy builds and deploys a Cloud Function from source. With --gen2 it uses the newer Cloud Functions (built on Cloud Run), supporting HTTP and event triggers.

What it does

The command packages source from --source, builds it for the given --runtime, and deploys it with an entry point (--entry-point) and a trigger - HTTP (--trigger-http) or an event (--trigger-topic, --trigger-event-filters). --gen2 selects 2nd-gen functions; --region is required.

Common usage

Terminal
# Deploy a gen2 HTTP function
gcloud functions deploy my-fn \
  --gen2 \
  --runtime=nodejs20 \
  --region=us-central1 \
  --source=. \
  --entry-point=handler \
  --trigger-http \
  --allow-unauthenticated

# Pub/Sub-triggered function
gcloud functions deploy on-msg --gen2 --runtime=python312 \
  --region=us-central1 --trigger-topic=jobs --entry-point=on_message

Common error in CI: build failed / entry point not found / API disabled

Deploys fail with "Build failed ... function \"handler\" is not defined in the provided module" (entry-point name mismatch) or "Cloud Functions API has not been enabled". Fix: ensure --entry-point exactly matches the exported function name, enable the required APIs (gcloud services enable cloudfunctions.googleapis.com run.googleapis.com cloudbuild.googleapis.com), and grant the build/runtime service accounts their roles. Pin --runtime to a supported version (e.g. nodejs20, python312) - deprecated runtimes are rejected.

Key options

OptionPurpose
--gen2Use 2nd-gen Cloud Functions
--runtimeLanguage runtime (e.g. nodejs20)
--entry-pointExported function to invoke
--trigger-httpHTTP-triggered function
--trigger-topicPub/Sub-triggered function
--regionRequired deploy region

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →