User Guide (API Version 2015-07-09)

Tutorial: Create a Pipeline That Builds and Tests Your Android App When a Commit Is Pushed to Your GitHub Repository

You can use AWS CodePipeline to configure a continuous integration flow in which your app is built and tested each time a commit is pushed to its repository. This tutorial shows how to create and configure a pipeline to build and test your Android app with source code in a GitHub repository. The pipeline detects the arrival of a new commit through webhooks that CodePipeline configures for your GitHub repository, and then uses CodeBuild to build the app and Device Farm to test it.


Many of the actions you add to your pipeline in this procedure involve AWS resources that you need to create before you create the pipeline. AWS resources for your source actions must always be created in the same AWS Region where you create your pipeline. For example, if you create your pipeline in the US East (Ohio) Region, your CodeCommit repository must be in the US East (Ohio) Region.

You can add cross-region actions when you create your pipeline. AWS resources for cross-region actions must be in the same Region where you plan to execute the action. For more information about cross-region actions, see Add a Cross-Region Action in CodePipeline.

You can try this out using your existing Android app and test definitions, or you can use the sample app and test definitions provided by Device Farm.

      The Step 2: Source page in the CodePipeline pipeline wizard

Configure Add definitions Push Build and Test Report
Configure pipeline resources Add build and test definitions to your package Push a package to your repository App build and test build output artifact kicked off automatically View test results

Configure CodePipeline to Use Your Device Farm Tests

  1. Add and commit a file called buildspec.yml in the root of your app code, and push it to your repository. CodeBuild uses this file to perform commands and access artifacts required to build your app.

    version: 0.2 phases: build: commands: - chmod +x ./gradlew - ./gradlew assembleDebug artifacts: files: - './android/app/build/outputs/**/*.apk' discard-paths: yes
  2. (Optional) If you use Calabash or Appium to test your app, add the test definition file to your repository. In a later step, you can configure Device Farm to use the definitions to carry out your test suite.

    If you use Device Farm built-in tests, you can skip this step.

  3. To create your build project in CodeBuild, do the following:

    1. Sign in to the AWS Management Console and open the CodeBuild console.

    2. If a welcome page is displayed, choose Get started.

      If a welcome page is not displayed, on the navigation pane, choose Build projects, and then choose Create build project.

    3. In Project name, enter a name for this build project.

    4. In Source provider, choose AWS CodePipeline.

    5. In Environment, choose Managed image. For Operating system, choose Ubuntu.

    6. For Runtime, choose Android. For Version, choose aws/codebuild/android-java-8:26.1.1. CodeBuild uses this OS image, which has Android Studio installed, to build your app.

    7. For Service role, choose your CodeBuild service role.

    8. For Build specifications, choose Use the buildspec.yml in the source code root directory.

    9. Choose Create build project. This creates a CodeBuild project that uses the buildspec.yml in your repository for configuration. The build project uses a service role to manage AWS service permissions. This step might take a couple of minutes.

  4. To create your pipeline and add a source stage, do the following:

    1. Sign in to the AWS Management Console and open the CodePipeline console at

    2. Choose Create pipeline. On the Step 1: Choose pipeline settings page, in Pipeline name, enter the name for your pipeline.

    3. In Service role, leave New service role selected, and leave Role name unchanged. You can also choose to use an existing service role, if you have one.


      If you use a CodePipeline service role that was created before July 2018, you need to add permissions for Device Farm. To do this, open the IAM console, find the role, and then add the following permissions to the role's policy. For more information, see Add Permissions for Other AWS Services.

      { "Effect": "Allow", "Action": [ "devicefarm:ListProjects", "devicefarm:ListDevicePools", "devicefarm:GetRun", "devicefarm:GetUpload", "devicefarm:CreateUpload", "devicefarm:ScheduleRun" ], "Resource": "*" }
    4. In Artifact location, do one of the following:

      1. Choose Default location to use the default artifact store, such as the Amazon S3 artifact bucket designated as the default, for your pipeline in the region you have selected for your pipeline.

      2. Choose Custom location if you already have an existing artifact store you have created, such as an Amazon S3 artifact bucket, in the same region as your pipeline.


      This is not the source bucket for your pipeline's source code. This is the artifact store for your pipeline. A separate artifact store, such as an Amazon S3 bucket, is required for each pipeline, in the same region as the pipeline.

    5. Choose Next.

    6. On the Step 2: Add source stage page, in Source provider, choose GitHub, and then choose Connect to GitHub.

    7. In the browser window, choose Authorize aws-codesuite. This allows your pipeline to make your repository a source, and to use webhooks that detect when new code is pushed to the repository.

    8. In Repository, choose the source repository.

    9. In Branch, choose the branch that you want to use.

    10. Choose Next.

  5. In Build, add a build stage:

    1. In Build provider, choose AWS CodeBuild.

    2. In CodeBuild, choose Project name, and then enter a name for your project.

    3. Choose Next.

    4. On the Step 4: Add deploy stage page, choose Skip deploy stage, and then accept the warning message by choosing Skip again. Choose Next.

    5. On Step 5: Review, choose Create pipeline. You should see a diagram that shows the source and build stages.

                View your pipeline.
  6. Add a Device Farm test action to your pipeline:

    1. In the upper left, choose Edit.

    2. At the bottom of the diagram, choose + Add stage.

    3. Enter a stage name, and then choose + Add action group.

    4. In Action name, enter a name.

    5. In Action provider, choose AWS Device Farm.

                Add a Device Farm test action to your pipeline.
    6. In ProjectId, choose your existing Device Farm project or choose Create a new project.

    7. In DevicePoolArn, choose your existing device pool. If you create a device pool, you must select a set of test devices.

    8. In App type, choose Android.

                Configure CodePipeline to use Device Farm as a test provider for stages of your
    9. In App file path, enter the path of the compiled app package. The path is relative to the root of the input artifact for the test stage. Typically, this path is similar to app-release.apk.

    10. In Test type, do one of the following:

      • If you're using one of the built-in Device Farm tests, choose the type of test configured in your Device Farm project.

      • If you aren't using one of the built-in Device Farm tests, choose your type of test, and then in Test file path, enter the path of the test definition file. The path is relative to the root of the input artifact for your test.

                Device Farm test types.
    11. In the remaining fields, provide the configuration that is appropriate for your test and application type.

    12. (Optional) In Advanced, provide configuration information for your test run.

                Advanced Device Farm configurations.
    13. In Input artifacts, choose the input artifact that matches the output artifact of the stage that comes before the test stage.

                Advanced Device Farm configurations.

      In the AWS CodePipeline console, you can find the name of the output artifact for each stage by hovering over the information icon in the pipeline diagram. If your pipeline tests your app directly from the Source stage, choose MyApp. If the pipeline includes a Build stage, choose MyAppBuild.

                Advanced Device Farm configurations.
    14. At the bottom of the panel, choose Add Action.

    15. In the AWS CodePipeline pane, choose Save pipeline change, and then choose Save change.

    16. To submit your changes and start a pipeline build, choose Release change, and then choose Release.