You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab CI Flutter iOS项目配置报错:variables格式问题排查

问题原因与修复方案

问题所在

你在.gitlab-ci.yml的variables里定义ver时使用了带options的嵌套结构,但GitLab CI的配置文件不支持这种写法——配置文件中的variables只能是简单的键值对哈希,带可选值的变量需要在GitLab项目的CI/CD设置中配置,不能直接写在yml文件里。另外原配置中${{ver}}是GitHub Actions的语法,GitLab CI里直接用${ver}或$ver即可。

修复方式

方式一:改为固定值变量(适合不需要版本选择的场景)

把ver设为固定字符串,直接写入配置文件:

stages:
  - build_android
  - build_ios
  - run_test

variables:
  ver: "13"

build_android:
  stage: build_android
  script:
    - flutter build apk

build_ios:
  before_script:
    - export DEVELOPER_DIR=/Applications/Xcode_${ver}.app/Contents/Developer
  stage: build_ios
  script:
    - xcode-select -s $DEVELOPER_DIR
    - flutter build ios --no-codesign

run_test:
  stage: run_test
  script:
    - flutter test

方式二:保留版本可选功能(通过项目后台配置实现)

  1. 删除.gitlab-ci.yml中variables块里的ver定义;
  2. 进入GitLab项目后台,打开设置 > CI/CD > 变量;
  3. 添加变量ver,设置默认值为13,并在「可选值」栏填入13,13.1,13.2,13.2.1,14.0.1(用逗号分隔);
  4. 修正后的.gitlab-ci.yml内容:
stages:
  - build_android
  - build_ios
  - run_test

build_android:
  stage: build_android
  script:
    - flutter build apk

build_ios:
  before_script:
    - export DEVELOPER_DIR=/Applications/Xcode_${ver}.app/Contents/Developer
  stage: build_ios
  script:
    - xcode-select -s $DEVELOPER_DIR
    - flutter build ios --no-codesign

run_test:
  stage: run_test
  script:
    - flutter test

内容的提问来源于stack exchange,提问作者Yunnane

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 09:36:10