Deploying from Source Control

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 hosted 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-url command line argument. You must also include the --source-path argument, as well as one of --source-branch, --source-tag, or --source-revision to indicate the location of your function source:

gcloud beta functions deploy <NAME> \
  --source-url https://source.developers.google.com/p/<PROJECT_ID>/r/<REPOSITORY_ID> \
  --source-path <SOURCE> <TRIGGER> [<SOURCE_BRANCH>|<SOURCE_TAG>|<SOURCE_REVISION>]

Let's look at the arguments in this command:

Argument Description
deploy The Cloud Functions command you are executing, in this case the deploy command.
<NAME> The name of the Cloud Function you are deploying. This name can only contain letters, numbers, underscores, and hyphens. Unless you specify the --entry-point option, your module must export a function with the same name.
--source-url https://source.developers.google.com/p/<PROJECT_ID>/r/<REPOSITORY_ID> The URL for the project's Cloud Source Repository. This should be in the form https://source.developers.google.com/p/<PROJECT_ID>/r/<REPOSITORY_ID>, where <PROJECT_ID> is your Cloud Project ID and <REPOSITORY_ID> is the name of your Cloud Source repository (for example, https://source.developers.google.com/p/my-project/r/default).
<TRIGGER> The trigger type for this function (see Calling Cloud Functions).
--source-path <SOURCE> The path within your source tree that contains your function. For example, "/functions".
--source-branch <SOURCE_BRANCH> The name of the branch containing your function source. You must also define at least one of branch, tag or revision.
--source-tag <SOURCE_TAG> The name of the tag containing your function source. You must also define at least one of branch, tag or revision.
--source-revision <SOURCE_REVISION> The name of the revision (commit) containing your function source. You must also define at least one of branch, tag or revision.
--entry-point <FUNCTION_NAME> The name of a function that should be used as an entry point, instead of the <NAME> argument that is used by default. Use this optional argument when the function exported in your source file has a different name than the <NAME> argument you're using to deploy.

Send feedback about...

Cloud Functions Documentation