Back to results for “CI/CD”
Flutter › CI/CD Pipelines for Flutter Apps

How can build caching within a CI/CD pipeline significantly reduce the total time needed to complete each individual pipeline run for a Flutter project?

Advanced

Answer

A Flutter build pipeline typically involves fairly time consuming steps, such as downloading and resolving all of a project's Dart package dependencies and compiling native Android and iOS build artifacts, and configuring your CI platform to properly cache these dependencies and intermediate build outputs between separate pipeline runs, rather than starting completely from scratch every single time, can dramatically reduce the total time each pipeline run actually takes to complete, which becomes especially valuable and noticeable for a busy team running the pipeline many times throughout a typical working day.
- uses: actions/cache@v3
  with:
    path: |
      ~/.pub-cache
      build/
    key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }}
Real-world example A team notices their CI pipeline consistently takes over ten minutes per run, and after properly configuring dependency and build caching, reduces that same pipeline's typical run time down to under three minutes for most subsequent runs.

Common follow-ups: What specific Flutter and Dart related directories are most valuable to cache?;How do you correctly invalidate a cache when the underlying dependencies genuinely change?