Deploying Cloud Functions from Cloud Source Repositories

This topic describes how to deploy Cloud Functions using code that is version controlled in Cloud Source Repositories.

By integrating Cloud Functions with Cloud Source Repositories, you can use Cloud Source Repositories to version control the code that contains your function. As the function changes over time, you can continue to access previous commits to see how the function changed and when.

Create and Deploy the function

With your code stored in Cloud Source Repositories, your next step is to create and deploy it. You can perform these tasks either with the GCP Console or the Cloud SDK.

GCP Console

  1. Go to Cloud Functions Overview page in the console.

    Make sure that the project for which you enabled Cloud Functions is selected.

  2. Click Create function.

    Screenshot that shows how to start function creation process

  3. In the Name field, type a name for your Cloud Function.

  4. In the Trigger field, select from the following:

    • HTTP Trigger
    • Cloud Pub/Sub topic
    • Cloud Storage bucket
  5. In the Source code field, select Cloud Source Repository.

  6. In the Repository field, type the name of your repository.

  7. From the Branch/Tag options, select the branch or tag that contains the version of the source code for your function. Then, in the next field, type the name of the branch or tag.

  8. In the Directory with Source Code field, type the path to where the function code exists in your repository.

  9. In the Function to Execute field, type the name of the function.

  10. Click Create.

While the function is being deployed, the icon next to it is a small spinner. After it finishes deploying, the spinner turns to a green check mark.

Cloud SDK

From a terminal window, type the following command. Note that you must modify this command with the project ID, repository ID, and source path.

gcloud beta functions deploy [FUNCTION_NAME] \
--source https://source.developers.google.com/projects/[PROJECT_ID]/repos/[REPOSITORY_ID]/moveable-aliases/master/paths/[SOURCE] \
--trigger-http;

Where:

  • [FUNCTION_NAME] is the name of the function you want to deploy
  • [PROJECT_ID] is the ID of your GCP project
  • [REPOSITORY_ID] is the name of your repository
  • [SOURCE] is the path to your source files
  • [TRIGGER] is the type of trigger the Cloud Functions uses

Test the function

With your function deployed, you can use either the GCP Console or the Cloud SDK to test it.

GCP Console

  1. Go to Cloud Functions Overview page in the console.

    Make sure that the project for which you enabled Cloud Functions is selected.

  2. Click the name of your function.

    The Function Details screen opens.

  3. Click the Testing tab.

  4. Click Test this function.

Cloud SDK

From a terminal window, type the following command:

gcloud beta functions call [FUNCTION_NAME]

For more information on deploying Cloud Functions to Cloud Source Repositories, see Deploying from Source Control in the Cloud Functions documentation.

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Source Repositories