Quickstart for Automating App Engine Deployments with Cloud Build

This topic describes how to automatically deploy an application stored in Cloud Source Repositories to App Engine when there is a new commit.

Before you begin

  1. Complete the steps from Quickstart Creating a Repository.

    After you complete the quickstart, you will have an application you can deploy to App Engine.

  2. Enable the Cloud Build API.

    Enable the API

Deploy your application

  1. From a terminal window, navigate to the directory containing the repository.

    cd hello-world
    
  2. Deploy the sample application.

    gcloud app deploy app.yaml
    
  3. Verify that your application is running.

    gcloud app browse
    

    The browser window should now read:

    Hello world!
    

Create a cloudbuild.yaml file

  1. From a terminal window, navigate to the directory containing the repository.

    cd hello-world
    
  2. Using a text editor, create a file named cloudbuild.yaml and paste the following:

    steps:
    - name: "gcr.io/cloud-builders/gcloud"
      args: ["app", "deploy"]
    timeout: "1600s"
    

Add the cloudbuild.yaml file to your repository

  1. Add the file to the repository.

    git add .
    
  2. Commit the file.

    git commit -m "Add cloudbuild.yaml file"
    
  3. Add the contents of the local Git repository to Cloud Source Repositories using the git push command:

    git push origin master
    

Create a build trigger

  1. Open the Cloud Build page in the Google Cloud Platform Console.

    Open the Cloud Build page

  2. Select your project and click Open.

  3. Click Create trigger.

  4. Select Cloud Source Repository.

  5. From the list of available repositories, select the hello-world repository, then click Continue.

  6. In the Name box, type:

    App Engine Test
    
  7. Under Trigger type, select Branch.

  8. Under Build Configuration, select cloudbuild.yaml.

  9. In the cloudbuild.yaml location box, type:

    /cloudbuild.yaml
    
  10. Click Create Trigger.

Push a change to your application

  1. From a terminal window, use a text editor to update the main.py file to read as follows:

    #!/usr/bin/env python
    
    import webapp2
    
    class MainHandler(webapp2.RequestHandler):
        def get(self):
    self.response.write('I update automatically!')
    
    app = webapp2.WSGIApplication([
        ('/', MainHandler)
    ], debug=True)
    
  2. Add the file to Git.

    git add .
    
  3. Commit the file.

    git commit -m "Update app to demonstrate build triggers"
    
  4. Add the contents of the local Git repository to Cloud Source Repositories using the git push command:

    git push origin master
    

View your build in progress

  1. Open the Build triggers page in the Google Cloud Platform Console.

    Open the Build triggers page

  2. Select your project and click Open.

  3. In the left nav, click Build history.

A list of all builds opens. At the top is a new entry that represents the build that began after you pushed your change to Cloud Source Repositories. When the build is ready, a green checkmark appears next to the build entry.

Re-test your application

From, a terminal window, open your application:

gcloud app browse

The browser window now reads:

I update automatically!

Clean up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:

Delete the build trigger

  1. Open the Build triggers page in the Google Cloud Platform Console.

    Open the Build triggers page

  2. Select your project and click Open.

  3. Locate the trigger you created.

  4. Click the More button More button next to the trigger you want to delete.

  5. Select Delete.

Delete the repository

  1. Open the source view in the console:

    Open the Source View in the Console

  2. Click the More button More button next to the repository you want to delete.

    Create Repository button

  3. Select Delete.

  4. When prompted for the repository name, enter hello-world and then click Delete.

What's next

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

Send feedback about...

Cloud Source Repositories