Edit on GitHub
Report issue
Page history

Deploy a Cloud Function with Cloud Build

Author(s): @montao ,   Published: 2020-07-29

Niklas Rosencrantz | DevOps/SRE

Contributed by the Google Cloud community. Not official Google documentation.

This tutorial demonstrates how to create and deploy a Cloud Function with Cloud Build.

Objectives

  • Use Cloud Build to deploy a Cloud Function.
  • Use code written in the Go programming language to process incoming HTTP requests.

Set up your environment

  1. Create a project in the Cloud Console.
  2. Enable billing for your project.
  3. Create a GitHub repository for your project.
  4. Enable the Cloud Functions API:

    gcloud services enable cloudfunctions.googleapis.com
    
  5. Add the Cloud Build GitHub app to your GitHub account and repository.

  6. Create the directory and file structure in the GitHub repository.

    You can use the file tree from the source for this tutorial as a starting point.

    Put a file named cloudbuild.yaml in the root directory and the code for the Cloud Function in a separate directory, as in the following file tree:

    │   .gitignore
    │   cloudbuild.yaml
    └───code
            function.go
    

Connect the repository with Cloud Build

  1. In the Cloud Console, go to the Cloud Build page.
  2. Choose Triggers.
  3. Click Connect repository.
  4. Create a push trigger so that Cloud Build will run when you push to the master branch.

After you have connected the repository with Cloud Build, Cloud Build will run, build, test, and deploy your Cloud Function each time you push to the repository.

You can view a list of your builds on the Cloud Builds page of the Cloud Console.

Submit a tutorial

Share step-by-step guides

Submit a tutorial

Request a tutorial

Ask for community help

Submit a request

View tutorials

Search Google Cloud tutorials

View tutorials

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.