Deploying from Cloud Source 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
- Follow the Cloud Source Repositories getting started steps to set up your repository.
- 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
Note that to read source repositories, your account (the account running
functions deploy) must have inherited or direct permissions on the repository.
This is especially important to remember when deploying as a service account or
from another project. Neither the
gcf-robot account nor the Cloud Build
account is used to read from the source repository; it's the actual user account
that is deploying the function.
To deploy a function from your source repo, use the
--source command line
gcloud functions deploy NAME \ --source https://source.developers.google.com/projects/PROJECT_ID/repos/REPOSITORY_ID/moveable-aliases/master/paths/SOURCE \ --runtime RUNTIME \ TRIGGER... \ [FLAGS...]
The command uses the following arguments to
gcloud functions deploy:
||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,
||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
||The name of the runtime you are using. For a complete list, see the
||If you have an HTTP function, use the flag
If you have an event-driven function, use the flags
||(Optional) Additional flags you can specify during deployment, such as
- Calling HTTP Functions.
- Calling Cloud Storage Trigger Functions.
- Calling Cloud Pub/Sub Trigger Functions.
- HTTP Cloud Functions Tutorial.
- Cloud Functions with Cloud Storage Tutorial.
- Cloud Functions with Cloud Pub/Sub Tutorial.
- Deploying Cloud Functions automatically with CI/CD.