Deploying Cloud Functions from Cloud Source Repositories

This topic describes how to deploy Cloud Functions by 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 a function and deploy it. You can perform these tasks either with the Google Cloud Console or the Cloud SDK.


  1. Go to the Cloud Functions page.

    Go to the Cloud Functions page

    Ensure the Google Cloud project for which you enabled Cloud Functions is selected.

  2. Click Create function.

    Screenshot that shows how to start function creation process

  3. On the Create function page, fill out the following options:

    • In the Name field, type a name for your Cloud Functions.
    • In the Trigger drop-down list, select one of the following options:
      • HTTP
      • Pub/Sub
      • Cloud Storage
    • In the Source code list, select Cloud Source repository.
    • In the Repository field, type the name of your repository.
    • In the Branch/tag list, 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.
    • In the Directory with source code field, type the path to where the function code exists in your repository.
    • In the Function to execute field, type the name of the function.
  4. Click Create.

While the function is being deployed, a small spinner is displayed. When the deployment is finished, the spinner becomes a green check mark.

Cloud SDK

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

gcloud functions deploy [FUNCTION_NAME] \
--source[PROJECT_ID]/repos/[REPOSITORY_ID]/moveable-aliases/master/paths/[SOURCE] \


  • [FUNCTION_NAME] is the name of the function you want to deploy.
  • [PROJECT_ID] is the ID of your Google Cloud 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, for example, --trigger-http.

Test the function

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


  1. Go to Cloud Functions Overview page.

    Go to the Overview page

    Ensure the project for which you enabled Cloud Functions is selected.

  2. Click the name of your function.

    The Function details page opens.

  3. Click the Testing tab.

  4. Click Test the function.

Cloud SDK

From a terminal window, enter the following command:

gcloud functions call [FUNCTION_NAME]

Where [FUNCTION_NAME] is the name of the function you want to test.

What's next

For more information on deploying Cloud Functions to Cloud Source Repositories, see the following Cloud Functions documentation: