fluttergitlabgitlab-cicicd

How to Create Multiple runners for different flutter versions?


So there are two types of runners in Gitlab

  1. Specific Runners
  2. Shared Runners

I have used Specific Runner and created a runner instance with SHELL as my Executor. so my machine itself a runner now. In my Machine, flutter 3.10 is configured so it works well with the below script.

stages:
  - test # All jobs related for testing dsuch as Unit Test
  - build
  - deploy
#
flutter_test: # Name of the lane
  stage: test # type of stage
  script:
    - flutter test # Run Flutter tests
  tags:
    - flutter # Tags for runner
  only:
    - main

flutter_build_android_dev: #Job nameDd
  stage: build # kind of job
  before_script:
    - flutter packages get
    - flutter clean
  script:
    - flutter build apk --flavor=dev -t lib/application/main/main_dev.dart
  artifacts:
    paths:
      - build/app/outputs/flutter-apk/app-dev-release.apk
    expire_in: 1 day
  tags:
    - flutter
  only:
    - main
#
deploy_android_dev: #deployd
  stage: deploy
  dependencies:
    - flutter_build_android_dev
  script:
    - appcenter login --token $APPCENTER_API_TOKEN
    - appcenter distribute release -f build/app/outputs/flutter-apk/app-dev-release.apk -g Collaborators --app balajiramadoss/passion
  tags:
    - flutter
  only:
    - main

##
## build ios dev33e3
##dd
flutter_build_ios_dev:
  stage: build
  before_script:
    - flutter packages get
    - flutter clean
  script:
    - flutter build ipa --flavor=dev -t lib/application/main/main_dev.dart --export-method=ad-hoc
  artifacts:
    paths:
      - build/ios/ipa/StarterDev.ipa
    expire_in: 1 day
  tags:
    - flutter
  only:
    - main

deploy_ios_dev:
  stage: deploy
  dependencies:
    - flutter_build_ios_dev
  script:
    - appcenter login --token $APPCENTER_API_TOKEN
    - appcenter distribute release -f build/ios/ipa/StarterDev.ipa -g Collaborators --app balajiramadoss/starter
  tags:
    - flutter
  only:
    - main

Now another project requires flutter 3.7 how do I create a runner for the specific flutter version?


Solution

  • To support multiple Flutter versions with GitLab CI/CD, you would need to set up runners with different Flutter versions installed.
    That means:

    • installing the specific version of Flutter you need on the runner machine or use a version manager like fvm (Flutter Version Management) (install it with dart pub global activate fvm), from the leoafarias/fvm project.
    • registering a new runner on your GitLab instance for the project that requires the different Flutter version.
    • assigning tags to your runners to differentiate them, like flutter-3.10 and flutter-3.7.
    • specifying, in your .gitlab-ci.yml, the tag that corresponds to the runner with the version of Flutter you need.

    For each project, install the required Flutter version:

    fvm install 3.7 # for the project that needs Flutter 3.7
    fvm install 3.10 # for the project that needs Flutter 3.10
    

    In the .gitlab-ci.yml for the project that requires Flutter 3.7, use fvm to run Flutter commands:

    stages:
      - test
      - build
      - deploy
    
    flutter_test:
      stage: test
      script:
        - fvm use 3.7
        - fvm flutter test
      tags:
        - flutter-3.7
      only:
        - main
    
    # Rest of the .gitlab-ci.yml configuration
    

    Do not forget to tag the runner when you register it using the gitlab-runner register command, and provide the flutter-3.7 tag when prompted.

    +----------------+               +----------------+           +----------------+
    |                |  Specific     |                |  Shared   |                |
    | GitLab Server  +-------------->+ Runner Machine +<----------+ Other Projects |
    |                |  Runner       | (Flutter 3.10) |  Runner   | (Flutter 3.7)  |
    +----------------+               +----------------+           +----------------+
    

    For the updated .gitlab-ci.yml, you need to adjust the tags for each job to target the specific runner you want to use.
    You may also want to use fvm in your scripts to make sure the right Flutter version is being used.
    The tags in your script will target the specific runner by its tag.