Setup CI on Gitlab for Flutter
Asked Answered
Y

4

14

I am trying to setup CI for my flutter project on gitlab but I don't understand where to start or what I have to do. Can anyone help me? Thanks

Yep answered 29/1, 2019 at 8:40 Comment(2)
Google introduced Codemagic during Flutter IO (codemagic.io). I haven't tried it yet but it might useful to take a look.Cinchonize
@Cinchonize I am a regular user of Codemagic. It is super easy to configure and take builds, both iOS, and Android. I always recommend Codemagic among my developer circle.Timorous
P
15

I suggest to setup your GitLab CI integration for flutter treating the android and ios project folder by their own in order to build your APK or IPA or doing test with your GitLab CI.

To start having a clue on how to setup a CI for Android and iOS projects on GitLab I'll suggest you these readings:

Android:

iOS

UPDATE: using Fastlane

I've the above solutions running on my apps and so I know they work. But I've found these interesting official docs for flutter using Fastlane (they seem quite easier):

So I suggest to give them a try too.

Pending answered 29/1, 2019 at 9:1 Comment(5)
@PierreLeBrun I've also found (but not actually tried) some very nice docs (also official) using Fastlane. And fastlane could be easily integrated with GitLab. So give it a try!Pending
I have alreasy tried to use fastane and I suceeded in setting it up locally but have no idea how to move it to gitlab (using docker and such) so I was looking for alternatives. :)Yep
Thanks man, i didn't use fastlane but my CI works for android. Now I have a problem when i initialize gradle, can you help me or I create an other topic ?Yep
@PierreLeBrun best practice should be to create (or search if there is already one that target your issue) question. Btw I could help you with this issue too, if you post another question, let me know the link. I guess this should be tagged only GitLab and gradle and android or even gradle and android only.Pending
I create a new one (i don't find a topic on my issue). This is the link #54425374Yep
W
8

.gitlab-ci.yml in your repo root:

stages:
  - test

tests:
  image: cirrusci/flutter
  stage: test
  script:
  - flutter test

Weary answered 26/4, 2020 at 10:23 Comment(0)
C
0

cirrcusci/flutter is deprecated, but you could use instead: https://hub.docker.com/r/mobiledevops/flutter-sdk-image

stages:
  - lint

Flutter analyze:
  image: mobiledevops/flutter-sdk-image:3.10.1
  stage: lint
  script:
    - flutter analyze
Counterforce answered 26/10, 2023 at 17:48 Comment(1)
cirrcusci/flutter is not deprecated. They moved to ghcr.io/cirruslabs/flutter:3.13.9 to utilized Github packages. mobiledevops is the outdated one as it hasn't been update in months.Scottie
N
0

To start with GitLab CI, a great starting point is the official documentation of GitLab: https://docs.gitlab.com/ee/ci/pipelines/index.html

The main idea is to have a file named .gitlab-ci.yml at the root of your repository. It has to specify at least one stage. In the following example, I have two stages: test and deploy. The different stages are executed sequentially, meaning that one stage will only start if the previous one has finished and has not fail.

The different stages are composed of jobs. Each job has to be linked to a stage and describe an action that has to be performed during a stage. The different jobs of the same stage are executed in parallel. So if your different tasks depend on each other, you will need to put them in different stages, while you can put them all in the same stage if they are not dependent.

As an example, I will reuse the pipeline available in the documentation of the Odevio (https://odevio.com/) tool that allows to generate iOS flutter apps without owning a Mac: https://github.com/Odevio/Odevio-CICD/blob/master/doc_gitlab_cicd/.gitlab-ci.yml

stages:
  - test
  - deploy

.flutter_docker_image:
  image: "ghcr.io/cirruslabs/flutter:3.16.0"

code_quality-job:
  extends: .flutter_docker_image
  stage: test
  before_script:
    - export PATH="$PATH:$HOME/.pub-cache/bin"
    - flutter pub global activate dart_code_metrics
  script:
    - metrics lib -r codeclimate  > gl-code-quality-report.json
  artifacts:
    reports:
      codequality: gl-code-quality-report.json

flutter-test-job:
  extends: .flutter_docker_image
  stage: test
  before_script:
    - export PATH="$PATH:$HOME/.pub-cache/bin"
  script:
    - flutter test --coverage
    # - lcov --summary coverage/lcov.info
    - genhtml coverage/lcov.info --output=coverage
  #coverage: '/lines\.*: \d+\.\d+\%/'
  artifacts:
    name: coverage
    paths:
      - $CI_PROJECT_DIR/coverage
    expire_in: 4 days

deploy-odevio-job:
  stage: deploy
  image: "ruby:3.1"
  environment: production
  before_script:
    - apt-get update -qy
    - apt-get -y install zip unzip
  script:
    - >
      wget -qO - https://raw.githubusercontent.com/Odevio/Odevio-CICD/master/script_cicd.sh | 
      bash /dev/stdin $ODEVIO_API_KEY -d ./ -t ad-hoc -k AAAA -fv 3.16.0
  artifacts:
    name: "odevio_ipa_url"
    paths:
      - ./odevio_ipa_url.txt
    expire_in: 30 day
  only:
    # Depends on your git
    - main
    - master

Here, we have two stages: test and deploy. The stage test is composed of two jobs: code_quality-job and flutter-test-job. These jobs aims to check the quality of your code before going to the next stage. They use the image "ghcr.io/cirruslabs/flutter:3.16.0". The next stage is deploy and is composed of only one job: deploy-odevio-job. This job use the image "ruby:3.1" and is launched only when you add changes to your branch master or main. The goal of this job is to use the Odevio tool generate an IPA file, or to publish your app directly to the app store connect. You can see a usage of a repository variable with $ODEVIO_API_KEY. Such variables can be set in the repository settings or in a team settings.

Hope this helps !

Nonagenarian answered 2/2 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.