Deploying from Cloud Source Repositories

Cloud Repositories

If you prefer to deploy your function source code from a source repository like GitHub or Bitbucket, you can use Google Cloud Source Repositories to deploy functions directly from branches or tags in your repository.

Set up Cloud Source Repositories

  1. Follow the Cloud Source Repositories getting started steps to set up your repository.
  2. Connect your GitHub or Bitbucket repository by following the mirrored repository guide.

Once the connection between Cloud Source Repositories and your external repository is established, these repositories are kept synchronized so that you can commit to your chosen repository as you would normally.

Deploy using the gcloud tool

To deploy a function from your source repo, use the --source command line argument:

gcloud functions deploy NAME \
  --source \
  --runtime RUNTIME \
  TRIGGER... \

The command uses the following arguments to gcloud functions deploy:

Argument Description
NAME The registered name of the Cloud Function you are deploying. NAME can only contain letters, numbers, underscores, and hyphens. NAME can either be the name of a function in your source code, or it can be a custom string (for example, my-http-function). If you use a custom string, you must also use the --entry-point flag to specify a function contained in your code, to tell the deploy command what function to execute.
--source PATH The location of the source code to deploy. The location can be a reference to a source repository, a path in Google Cloud Storage, or a local filesystem path. For details, see the gcloud Command Reference.
--runtime RUNTIME The name of the runtime you are using. For a complete list, see the gcloud reference. Note that you must include this flag the first time you deploy a function, but you can omit it on subsequent deployments.
TRIGGER... If you have an HTTP function, use the flag --trigger-http.

If you have an event-driven function, use the flags --trigger-resource MY_RESOURCE and --trigger-event MY_EVENT. If your event-driven function is assigned a Pub/Sub trigger, you can instead use the shorthand --trigger-topic MY_TOPIC. Likewise, when deploying functions that are assigned Cloud Storage triggers, you can simply use the flag --trigger-bucket MY_STORAGE_BUCKET to trigger function execution whenever files in the specified bucket change.
FLAGS... (Optional) Additional flags you can specify during deployment, such as --stage-bucket or --entry-point. For a full reference, see the gcloud functions deploy documentation.

Next steps