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
# 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_messageCommon 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
| Option | Purpose |
|---|---|
| --gen2 | Use 2nd-gen Cloud Functions |
| --runtime | Language runtime (e.g. nodejs20) |
| --entry-point | Exported function to invoke |
| --trigger-http | HTTP-triggered function |
| --trigger-topic | Pub/Sub-triggered function |
| --region | Required deploy region |