AWS CodePipeline
User Guide (API Version 2015-07-09)

A new console design is available for this service. Although the procedures in this guide were written for the older version of the console, you will find many of the concepts and basic procedures in this guide still apply.

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

AWS CodePipeline enables you 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 AWS CodePipeline configures for your GitHub repository, and then uses AWS CodeBuild to build the app and Device Farm to test it.

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

      The Step 2: Source page in the AWS 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 AWS 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. AWS 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 pipeline and add a source stage, do the following:

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

    2. Choose Create pipeline, and then enter a name for your pipeline.

    3. In Source provider, choose GitHub, and then choose Connect to GitHub.

    4. 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.

    5. In Repository, choose the source repository.

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

    7. Choose Next step.

  4. In Build, add a build stage as follows:

    1. In Build provider, choose AWS CodeBuild, and then choose Connect to GitHub.

    2. In Configure your project, choose Create a new build project, and then in Project name, enter a name for your project.

    3. In Environment: How to build, choose Use an image managed by AWS CodeBuild. For Operating system, choose Ubuntu.

    4. For Runtime, choose Android. For Version, choose aws/codebuild/android-java-8:26.1.1. AWS CodeBuild uses this OS image, which has Android Studio installed, to build your app. For Build specification, choose Use the buildspec.yml in the source code root directory.

                Define the build stage for your pipeline.
    5. Choose Save build project. This creates an AWS 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.

    6. Choose Next step.

    7. In Deployment provider, choose No Deployment, and then choose Next step.

    8. In Service role name, choose AWS-CodePipeline-Service, and then choose Create role. This creates a service role for AWS CodePipeline to manage permissions to other AWS services.


      If you use an AWS 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": "*" }
    9. Choose Create pipeline. You should see a diagram that shows your pipeline source and build stages.

                View your pipeline.
  5. Add a Device Farm test action to your pipeline as follows:

    1. In the upper left, choose Edit.

    2. At the bottom of the diagram, choose + Stage.

    3. Enter a stage name, and then choose + Action.

    4. In Action category, choose Test.

    5. In Action name, enter a name.

    6. In Test provider, choose AWS Device Farm.

                Add a Device Farm test action to your pipeline.
    7. In Project name, choose your existing Device Farm project or choose Create a new project.

    8. In Device pool, choose your existing device pool or choose Create a new device pool. If you create a device pool, you need to select a set of test devices.

    9. In App type, choose Android.

                Configure AWS CodePipeline to use Device Farm as a test provider for stages of your
    10. 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.

    11. 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.
    12. In the remaining fields, provide the configuration that is appropriate for your test and application type.

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

                Advanced Device Farm configurations.
    14. 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.
    15. At the bottom of the panel, choose Add Action.

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

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