Mastering CI/CD with Bitrise: Integrating bitrise.yml into Your Git App Repository for Improved Workflow Management

Android|Apr 13, 2023|Last edited: May 4, 2023
  • Bitrise
  • CI/CD
  • GitHub
  • Git
  • Mastering CI/CD with Bitrise: Integrating bitrise.yml into Your Git App Repository for Improved Workflow Management
    type
    Post
    status
    Published
    date
    Apr 13, 2023
    slug
    storing-bitrise-yml-in-git
    summary
    Store the bitrise.yml file in your Git repository for version control, easy management and customization of CI/CD workflows, and confident local changes.
    tags
    Bitrise
    CI/CD
    GitHub
    Git
    category
    Android
    icon
    password

    Storing bitrise.yml in Git for Superior CI/CD Workflow Management of your App

    Continuous integration and continuous delivery (CI/CD) play a critical role in modern app development. One popular platform for managing these processes is Bitrise. In this blog post, we will explore how to add the bitrise.yml configuration file to your app repository for better version control and the ability to make changes locally. Let's dive in!
     

    Step 1: Copy bitrise.yml Content from Bitrise Web Page

     
    To start, navigate to the bitrise.yml tab on the Bitrise web page for your project. Click on “Store in app repository”. Click the button labeled "Copy the content of the current bitrise.yml file to the clipboard." This will allow you to add the content of the bitrise.yml file to your app directory locally.
     
    notion image

    Step 2: Create and Add bitrise.yml File in Android Studio

     
    Open your app in Android Studio and follow these steps:
    1. Switch to the Project View.
    1. Create a new file named "bitrise.yml" in the root directory of your project.
    1. Paste the copied content into the newly created bitrise.yml file.
     
    notion image
     

    Step 3: Update Triggers

     
    Ensure that your triggers are set up correctly. Go to the Triggers tab in Bitrise and click "Add your trigger." If prompted, click "Copy the content of the current bitrise.yml file to the clipboard" to copy the necessary content. Then, add the following code to your local bitrise.yml file:
     
    trigger_map: - push_branch: main workflow: Maestro-Test-Android
     
    notion image
    notion image
     

    Complete Code of bitrise.yml

    --- format_version: '11' default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git project_type: android workflows: Maestro-Test-Android: description: | Deploys app using [Deploy to bitrise.io Step](https://devcenter.bitrise.io/en/getting-started/getting-started-with-android-apps.html#deploying-an-android-app-to-bitrise-io-53056). Next steps: - Check out [Getting started with Android apps](https://devcenter.bitrise.io/en/getting-started/getting-started-with-android-apps.html) for signing and deployment options. - [Set up code signing with *Android Sign* Step](https://devcenter.bitrise.io/en/code-signing/android-code-signing/android-code-signing-using-the-android-sign-step.html). steps: - activate-ssh-key@4: {} - git-clone@7: {} - cache-pull@2: {} - install-missing-android-tools@3: inputs: - gradlew_path: "$PROJECT_LOCATION/gradlew" - android-build@1: inputs: - project_location: "$PROJECT_LOCATION" - module: "$MODULE" - variant: "$VARIANT" - cache_level: none - script: title: Print project location and APK output directory inputs: - content: | #!/bin/bash echo "Project location: $PROJECT_LOCATION" echo "APK output directory: $PROJECT_LOCATION/$MODULE/build/outputs/apk/$VARIANT/" - avd-manager@1: {} - wait-for-android-emulator@1: {} - script: title: Install Maestro and run e2e tests inputs: - content: |- #!/bin/sh set -ex # Maestro version if [[ -z "$maestro_cli_version" ]]; then echo "If you want to install a specific version of Maestro CLI, please set the environment variable maestro_cli_version to the version you want to install." else echo "Installing Maestro CLI version $maestro_cli_version" export MAESTRO_VERSION=$maestro_cli_version; fi # Install maestro CLI echo "Installing Maestro CLI" curl -Ls "https://get.maestro.mobile.dev" | bash export PATH="$PATH":"$HOME/.maestro/bin" echo "MAESTRO INSTALLED - Check Version" maestro -v $ANDROID_HOME/platform-tools/adb install "$BITRISE_APK_PATH" cd $PROJECT_LOCATION ls pwd echo "Running tests with Maestro" maestro test .maestro/dummy.yaml - sign-apk@1: run_if: '{{getenv "BITRISEIO_ANDROID_KEYSTORE_URL" | ne ""}}' - cache-push@2: {} - deploy-to-bitrise-io@2: {} meta: bitrise.io: stack: linux-docker-android-20.04 machine_type_id: standard app: envs: - opts: is_expand: false PROJECT_LOCATION: "." - opts: is_expand: false MODULE: app - opts: is_expand: false VARIANT: debug - opts: is_expand: false _JAVA_OPTIONS: "-Xms1024m -Xmx2048m" - opts: is_expand: false GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError" trigger_map: - push_branch: main workflow: Maestro-Test-Android
     

    Step 4: Commit and Push Changes to GitHub

     
    Commit all changes and push the updated code to your GitHub repository. Afterward, navigate to the bitrise.yml tab on Bitrise and click the "Update Settings" button. Bitrise should identify and validate your bitrise.yml file from your GitHub repository. Once validation is complete, the "Add bitrise.yml to the app repository" section should disappear.
     
    Click on Update settings button.
    Click on Update settings button.
    "Add bitrise.yml to the app repository" section  disappeared.
    "Add bitrise.yml to the app repository" section disappeared.
     

    Step 5: Trigger a New Build

     
    With your bitrise.yml file now stored in your Git repository, you can trigger a new build using the updated configuration. If you don't have any new changes to commit, create an empty commit with the command:
    git commit --allow-empty -m "Trigger Bitrise"
    Then, push the commit to your GitHub repository. Your build should start automatically. If it doesn't, double-check your Triggers section and ensure it is set up correctly in your local git version-controlled bitrise.yml file.

    Conclusion:

     
    By adding the bitrise.yml file to your app repository, you can now enjoy the benefits of version control and the ability to make changes locally. If you need to update your workflow and prefer using the web UI, Bitrise will conveniently prompt you to copy the content and paste it into your local git version-controlled bitrise.yml file. Remember to stage, commit, and push the changes to see the updates reflected in your Bitrise build. Happy building!
     
    Bitrise will conveniently prompt you to copy the content.
    Bitrise will conveniently prompt you to copy the content.
    Efficiently Running Maestro UI Tests in Bitrise for Your Android AppStreamline Your Android Development Workflow with Device Mirroring in Android Studio Giraffe