Edit on GitHub
Report issue
Page history

Cloud Functions GitHub Auto-deployer

Author(s): @ancavulpe ,   Published: 2017-07-26

## Introduction

This simple tutorial demonstrates using an HTTP Cloud Function to automatically re-deploy another HTTP Cloud Function stored on GitHub when a commit is pushed.


  • Prepare an HTTP Cloud Function in your GitHub repository.
  • Deploy an auto-deployer HTTP Cloud Function that watches changes in that repository.
  • Make a new commit to your GitHub repository and watch your HTTP Cloud Function be automatically re-deployed.


This tutorial uses billable components of [Cloud Platform][platform], including:

Use the Pricing Calculator to generate a cost estimate based on your projected usage.


  1. Create a project in the Google Cloud Platform Console.
  2. Enable billing for your project.
  3. Install the Google Cloud SDK.

Deploying the auto-deployer function

  1. Fork an existing github repo with hello world function.
  2. Clone the repository which contains the auto-deployer function.

    git clone https://github.com/GoogleCloudPlatform/community
  3. Change into the cloned directory:

    cd community/tutorials/cloud-functions-github-auto-deployer/auto-deployer
  4. Update the config.js file with your own values:

      "secretToken" : "[YOUR_SECRET_TOKEN]",
      "stageBucket" : "[YOUR_STAGING_BUCKET_NAME]",
      "location" : "[YOUR_REGION]",
      "deployments": [


    • [YOUR_SECRET_TOKEN] is the secret key you will configure in your GitHub webhook in order to validate the request.
    • [YOUR_STAGING_BUCKET_NAME] is the name of your staging Cloud Storage bucket.
    • [YOUR_REGION] is the region where your function is deployed.
    • [YOUR_REPOSITORY] is the owner/repo of the repository where the function to be deployed resides, e.g. GoogleCloudPlatform/nodejs-docs-samples.
    • [YOUR_FUNCTION_PATH] is the path of the HTTP Cloud Function in your GitHub repository, e.g. functions/helloworld
    • [YOUR_FUNCTION_NAME] is the name of the function that you want to be automatically deployed, e.g. helloGET.
  5. Run the following command to deploy the auto-deployer function:

    gcloud beta functions deploy githubAutoDeployer --stage-bucket [YOUR_STAGING_BUCKET_NAME] --trigger-http

    where [YOUR_STAGING_BUCKET_NAME] is the name of your staging Cloud Storage bucket.

Making a function in your repository auto-deployable

  1. To deploy an HTTP Cloud Function whenever a commit is pushed, create a webhook in your repository:

    1. Go to your GitHub repository.
    2. Clink on the Settings tab.
    3. Click on Webhooks option in the left panel.
    4. Click on Add webhook button and confirm by reintroducing your credentials.
    5. Enter the HTTP trigger URL of the auto-deployer function you just deployed into the Payload URL field, i.e. https://[YOUR_REGION]-[YOUR_PROJECT_ID].cloudfunctions.net/gitHubAutoDeployer, where [YOUR_REGION] is the region where your function is deployed and [YOUR_PROJECT_ID] is your Google Cloud project ID.
    6. For Content type select application/json.
    7. In the Secret textbox fill in the secret token you used in the config.json file (see [YOUR_SECRET_TOKEN] above) for validating the request.
    8. Make sure that Just the push event is selected for triggering the webhook.
    9. Click an Add webhook button.
  2. Update your repository and watch your function being re-deployed by the auto-deployer function:

    1. Modify the function in your repository.
    2. Push commit to your repository.
    3. Observe that the auto-deployer re-deploys your function.

Submit a Tutorial

Share step-by-step guides


Request a Tutorial

Ask for community help


GCP Tutorials

Tutorials published by GCP


Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates.