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
方式二:保留版本可选功能(通过项目后台配置实现)
- 删除
.gitlab-ci.yml中variables块里的ver定义; - 进入GitLab项目后台,打开设置 > CI/CD > 变量;
- 添加变量
ver,设置默认值为13,并在「可选值」栏填入13,13.1,13.2,13.2.1,14.0.1(用逗号分隔); - 修正后的
.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
相关产品推荐
相关产品推荐

