Automating Mobile App Deployment with Jenkins, Bitbucket, and Fastlane

Continuous Integration and Continuous Deployment (CI/CD) are essential practices for delivering mobile applications quickly and reliably. In this article, we will explore how to set up an automated pipeline using Jenkins and Bitbucket to deploy a Flutter application to both the Google Play Store (Android) and Apple App Store / TestFlight (iOS).

1. Why Automate Mobile App Deployment?

  • Reduce manual errors in builds and publishing.
  • Deliver updates faster with branch-based rules.
  • Ensure consistency between test and production releases.
  • Improve collaboration between developers, testers, and release managers.

2. Branching Strategy in Bitbucket

A clean branching strategy ensures controlled deployments:

  • test branch → Deploys automatically to TestFlight and Internal Testing in Google Play.
  • master branch → Deploys to Production (App Store & Play Store).

3. Jenkins Setup

Install Jenkins on a Linux server and configure:

  • Pipeline plugin (for Jenkinsfile support).
  • Bitbucket plugin (to trigger builds on push).
  • Credentials plugin (to securely store signing keys and API tokens).

4. Build Nodes: Linux + macOS

Mobile apps require different build environments:

  • Linux Node → Builds Android APK/AAB and deploys to Google Play.
  • Mac Node (e.g., MacBook Pro) → Builds iOS IPA and deploys to App Store/TestFlight.

Jenkins delegates build steps to the correct node based on the pipeline configuration.

5. Fastlane for Deployment

Fastlane is the industry-standard tool for automating mobile app distribution. Configure two lanes inside your ios/fastlane/Fastfile and android/fastlane/Fastfile:


  lane :beta do
    build_app(scheme: "Runner")
    upload_to_testflight
  end

  lane :release do
    build_app(scheme: "Runner")
    upload_to_app_store
  end
  

For Android, use supply to upload AAB/APK files to Google Play.

6. Jenkins Pipeline (Jenkinsfile)

Below is a simplified pipeline script:


  pipeline {
      agent none

      stages {
          stage('Android Build & Deploy') {
              agent { label 'linux' }
              steps {
                  sh '''
                    flutter clean
                    flutter pub get
                    flutter build appbundle --release
                    cd android && bundle exec fastlane beta
                  '''
              }
          }

          stage('iOS Build & Deploy') {
              agent { label 'mac' }
              steps {
                  sh '''
                    flutter clean
                    flutter pub get
                    flutter build ios --release --no-codesign
                    cd ios && bundle exec fastlane beta
                  '''
              }
          }
      }
  }
  

7. Secrets & Credentials

Store sensitive information securely in Jenkins:

  • Google Play: Service account JSON key.
  • Apple App Store: API key or Apple ID credentials.
  • Keystore & Certificates: Uploaded to Jenkins credentials store.

8. End-to-End Flow

  1. Developer pushes code to Bitbucket (test or master branch).
  2. Webhook triggers Jenkins pipeline.
  3. Android build runs on Linux node and deploys via Fastlane.
  4. iOS build runs on Mac node and deploys via Fastlane.
  5. Team gets the app automatically on TestFlight or Play Store Internal Testing.


Conclusion

By combining Jenkins, Bitbucket, Fastlane, and a dual-node architecture (Linux + macOS), you can achieve fully automated deployments for both Android and iOS apps. This reduces release friction, increases reliability, and allows your team to focus more on building features rather than handling manual releases.

Automation is not just about speed; it’s about consistency and confidence in every release.

Post a Comment

0 Comments