Flutter CI with Gitlab


Getting up and running with Gitlab CI is quick and easy. I found cirrusci has a great collection of prebuilt Flutter docker images! These images are a bit on the heavy side at ~1.3GB, however, they are great off the shelf solution to get running CI quickly.

In a previous post, How to pull a private NPM dependency with Gitlab CI, I showed how I pull private NPM dependencies. When I started with Flutter I figured this same approach would work.

I was wrong!

Again I am using a private repo to host private code. My pubspec.yaml looks like the below. I simply point my dependency to a git hash. Simple enough. This worked fine on my local machine.

    sdk: flutter

      url: git@gitlab.com:kmcgill88/my-repo.git
      ref: 692c68ac373d05b00e39d076a8b00fa12c4ff8e8

The above reference failed in Gitlab CI since flutter packages get is using git in the background to pull this dependency. My private ssh is installed on my local machine but not in the docker container running the build.

I found an easy trick to use the Gitlab CI build credentials supplied to every Gitlab build. git to the rescue! git config --global url. and .insteadOf (see before_script below). This solution allows me to keep the git ssh approach while running on my local machine and clone this private pub package during build time.

image: cirrusci/flutter:v1.12.13-hotfix.5

  - test

  - git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/kmcgill88/my-repo.git".insteadOf git@gitlab.com:kmcgill88/my-repo.git

  stage: test
    - flutter packages get
    - flutter analyze
    - flutter test
    - docker