Continuous Deployment to App Engine Using Bitbucket Pipelines

This topic shows you how to set up a continuous delivery pipeline using Bitbucket and Google App Engine.


  • Understanding a sample application.
  • Creating authentication credentials for Bitbucket.
  • Creating a Bitbucket repository.
  • Creating a continuous delivery pipeline to App Engine.
  • Testing the pipeline.


This tutorial uses billable components of Google Cloud Platform (GCP), including:

  • App Engine

App Engine has free quotas that might cover this tutorial in a live production environment. Use the Pricing Calculator to generate a cost estimate based on your projected usage for this tutorial.

Before you begin

  1. Select or create a GCP project.

    Go to the Manage resources page

  2. Make sure that billing is enabled for your project.

    Learn how to enable billing

  3. Enable the App Engine Admin API and Google Books API APIs.

    Enable the APIs

  4. Create a Bitbucket account if you don't have one already.

Understanding the application

This tutorial demonstrates a Python app that runs on App Engine with Flask, a Python web framework, and interacts with the Google Books API. The sample app has a simple Python Flask endpoint that looks up the author of a book by its title.

Creating authorization credentials for Bitbucket

Create an App Engine service account and API key. Bitbucket needs this information to deploy to App Engine.

Creating an App Engine service account

  1. In the Google Cloud Platform Console, go to the Credentials page.

    Go to the credentials page.

  2. Click Create credentials > Service account key.

  3. In the Service account dropdown, select New service account.

  4. In the Service account name field, input Bitbucket authorization.

  5. In the Role dropdown, select the following roles:

    • App Engine > App Engine Admin
    • Storage > Storage Object Admin
  6. Click the Create button. A copy of the JSON file downloads to your computer.

Creating an API Key

  1. Click Create credentials > API key.

  2. Copy the value that displays in the Your API key field. Use this value below when setting up environment variables.

Create an App Engine application

The pipeline script expects your project to have an App Engine application. To create an App Engine application:

  1. In the GCP Console, go to Cloud Shell.

    Go to Cloud Shell

  2. Run the following command to create your default App Engine application:

    gcloud app create

Importing the tutorial repository in Bitbucket

  1. Navigate to Bitbucket and log in.

  2. Click Repositories in the left navigation.

  3. Click the + button, then click Repository.

  4. Click Import repository.

  5. Select Git from the Source dropdown.

  6. Input into the URL field.

  7. Click the Import repository button.

Creating the pipeline to App Engine

To create the pipeline, follow the Atlassian instructions to enable Bitbucket Pipelines. Don't try to run a pipeline yet.

Next, you would typically configure the pipeline by editing the bitbucket-pipelines.yml file. Because the repository you imported contains an already-configured version of the bitbucket-pipelines.yml file, you don't need to complete any additional pipeline configuration steps for this tutorial.

Finally, configure the environment variables required by the pipeline script:

  1. In Bitbucket's left navigation menu, click Settings.
  2. In the Settings page's navigation menu, under the PIPELINES heading, click Environment variables.
  3. Add the following three environment variables:

    • Input CLOUDSDK_CORE_PROJECT in the Type variable field. Input your Cloud Platform project ID in the Type value field. Click the Add button.

    • Input GOOGLE_API_KEY in the Type variable field. Input the value of the API key you created earlier in the Type value field. Click the Add button.

    • Input GOOGLE_CLIENT_SECRET in the Type variable field. Open the JSON file you downloaded in the Creating an App Engine service account section, and paste the file's contents into the Type value field. Click the Add button.

Testing the pipeline

Now that your pipeline is fully configured, test that the pipeline triggers as expected when changing the source code.

  1. Click Source in the left navigation.

  2. Click the file name, then click the Edit button to edit the file.

  3. Change the text "This repo" to "This repository" on line 5.

  4. Click the Commit button, then click the Commit button in the dialog.

  5. Click Pipelines in the left navigation. You will see a pipeline entry associated with the latest commit.

  6. Click the pipeline entry to see details about the pipeline status.

  7. Wait until the pipeline status string changes to Successful. This indicates the application changes deployed successfully.

To manually verify that the application deployed, navigate to the following URL in a web browser. Replace [YOUR_PROJECT_ID] with your project ID.


The text "James Joyce" displays.

You can test the app further by replacing the word "ulysses" in the URL with a different book title.

Cleaning up

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

Deleting the project

The easiest way to eliminate billing is to delete the project you created for the tutorial.

To delete the project:

  1. In the GCP Console, go to the Projects page.

    Go to the Projects page

  2. In the project list, select the project you want to delete and click Delete project. After selecting the checkbox next to the project name, click
      Delete project
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

What's next

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

Send feedback about...