Sub topic 14
Automating the Release Pipeline
This chapter assumes that you can build a Flutter app locally, use Git, and run flutter commands from a terminal. You also need Android signing configured for Android releases. iOS publishing requires a macOS runner with Xcode and access to your Apple Developer account.
A continuous integration and continuous delivery (CI/CD) pipeline is an automated workflow that checks code, builds release artifacts, and optionally publishes them. Continuous integration runs checks whenever code changes. Continuous delivery prepares a release for review or publication.
What the pipeline should do
A release pipeline commonly follows this order:
- Check out the repository.
- Install the required Flutter, Java, and Xcode versions.
- Run formatting, static analysis, and tests.
- Restore signing credentials from protected secrets.
- Build Android and iOS release artifacts.
- Store the artifacts for review.
- Publish an approved build to Google Play or TestFlight.
Keep verification before publishing. A failed test should prevent a release from reaching a store.
Separate checks from publishing
Run checks on every pull request, but publish only from a protected branch or a version tag. This prevents an unfinished feature from being uploaded accidentally.
A simple release script can make the local and CI procedures consistent:
#!/usr/bin/env bash
set -euo pipefail
flutter pub get
dart format --output=none --set-exit-if-changed .
flutter analyze
flutter test
: "${API_BASE_URL:?Set API_BASE_URL before building}"
flutter build appbundle --release \
--dart-define="API_BASE_URL=${API_BASE_URL}" \
--obfuscate \
--split-debug-info=build/symbolsThe set -euo pipefail options stop the script when a command fails or a required variable is missing. The pipeline should upload both the App Bundle and build/symbols as protected artifacts. Symbol files are needed to decode obfuscated crash reports.
Protect secrets and versions
CI systems provide encrypted secret storage. Put keystore files, passwords, signing certificates, provisioning profiles, and store credentials there. Do not print them in logs or commit them to Git.
Use a short-lived publishing credential when the store supports one. Give the credential only the permissions required to upload builds. Rotate it when a team member leaves or when exposure is suspected.
Each store upload needs a new build number. Keep the human-readable version and build number together in pubspec.yaml, or generate the build number from the CI run:
flutter build appbundle --release \
--build-name=1.2.0 \
--build-number="${GITHUB_RUN_NUMBER}"The same release identifier should be used when building Android and iOS. This makes a failed upload easier to identify and prevents accidental reuse of an existing store version.
> callout note > Never treat a CI log as private. Mask secrets, avoid shell tracing around credentials, and verify that generated artifacts do not contain key files or secret configuration.
Android and iOS jobs
Android builds can run on Linux or macOS. iOS builds require macOS because Xcode must create and sign the archive. A practical pipeline uses separate jobs that share the same commit, version, and environment configuration.
Build Android with flutter build appbundle --release. Build iOS with flutter build ipa --release. Configure signing on the runner before either command. After building, upload artifacts for a human to install and test.
Only publish after release testing succeeds. A later job can use Google Play service credentials for an internal testing track and App Store Connect credentials for TestFlight. Production publication should usually require a manual approval step.
Exercise
Exercise
Why should a pipeline keep publishing in a separate job after tests and builds?
Show answer
Separation makes failed checks stop publication and lets a protected approval control when a valid artifact reaches a store.