Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru

Triggering a Cloud Function with Cloud Build

Many organizations have adopted a CI/CD (continuous integration/continuous delivery) pipeline to maintain coding efficiency. Cloud Functions work well in a CI/CD environment and can be implemented as such through a Google Cloud service, Cloud Build. In this hands-on lab, you’ll gain the practical experience of setting up the Cloud Source Repository, Cloud Functions, and Cloud Build services to implement a CI/CD pipeline.


Path Info

Clock icon Beginner
Clock icon 45m
Clock icon Nov 17, 2021

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Enable APIs

    1. From the Google Cloud console's main navigation, visit APIs & Services > Library to enable the following services:
      • Cloud Functions
      • Source Repositories
      • Cloud Build
      • Cloud Resource Manager API
  2. Challenge

    Create a Google Cloud Source Repository

    1. Activate a Cloud Shell.

    2. Create a Source Repository:

      gcloud source repos create gcpro_repo
    3. Clone the repository to the shell:

      gcloud source repos clone gcpro_repo
    4. Clone repository from GitHub:

      git clone
    5. Copy files to shell repo:

      cp content-gcpro-developer/cicd-lab/* gcpro_repo
      cd gcpro_repo
  3. Challenge

    Move Files to Source Repository

    1. Use the following commands to commit the files in the shell repo to the newly created Source Repository:

      git remote add google[PROJECT_ID]/r/gcpro_repo
      git add .
      git config --global "[EMAIL_ADDRESS]"
      git config --global "[NAME]"
      git commit -m "Initial Commit"
      git push --all google
    2. Visit the Source Repositories dashboard and click gcpro_repo to confirm the files.

  4. Challenge

    Create Cloud Function

    1. From the main navigation, go to Cloud Functions.
    2. Choose Create function.
    3. Configure your function with the following values:
      • Environment: 1st gen
      • Name: repo-function-1
      • Trigger: HTTP
      • Authentication: Allow unauthenticated invocations
      • Click Save
      • Under Runtime, build, connections and security settings:
        • Maximum number of instances: 1
      • Click Next
      • Source Code: Cloud Source repository
      • Runtime: Python 3.7
      • Repository: gcpro_repo
      • Entry point: greetings_http
    4. Leave all other fields with their default values and click Deploy.
    5. Once the function spins up, click to open it.
    6. Select the Trigger tab, and click the listed URL. It will open a new window with the default greeting.
    7. Back in the GCP console, click the Testing tab.
    8. In the Triggering window, enter
    1. Click Test the function.
    2. In the Output box, note the results.
  5. Challenge

    Set IAM Permissions

    1. From the navigation, go to Cloud Build > Settings.
    2. In the Service Account Permissins section, change the status of the Cloud Functions Developer role to Enabled.
    3. In the Additional steps may be required dialog, choose Grant Access to All Service Accounts.
    4. Note that the status of the Service Account User role has changed to Enabled.
  6. Challenge

    Define a Cloud Build Trigger

    1. From the side navigation of the Cloud Build console, go to Triggers.
    2. Click Create trigger.
    3. Set the following values:
      • Repository: gcpro_repo.
      • Name: trigger-1
      • Build configuration: Cloud Build configuration file (yaml or json)
        • Make sure Cloud Build configuration file location autopopulates with / cloudbuild.yaml.
    4. Leave all other fields with their default values, and click Create.
  7. Challenge

    Verify Trigger

    1. From the Cloud Build Triggers page, click the Run Trigger option associated with the newly defined trigger.
    2. Test the trigger by using the Cloud Shell editor to alter the file and pushing to the Source Repository.
    3. Visit Cloud Build > History and, if necessary, refresh the page to confirm the new build.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans