我在我的 Flutter 移动应用项目中有来自 GitLab 的私有依赖。它在 pubspec.yaml
中使用 git 存储库链接指定,如果我使用 ssh,我可以成功运行 pub get
(我已生成 ssh 密钥并将其添加到我的 gitlab 帐户)
my_private_package:
git:
url: ssh://git@************/my_private_package.git
现在我想用 AppCenter 构建我的应用程序并部署到商店。在 AppCenter 构建阶段无法使用 ssh 密钥,所以我看到的唯一可行的解决方案是使用 GitLab Deploy Token 作为环境变量从 AppCenter 机器访问我的私有包。用于访问存储库的 Git 链接变为:
my_private_package:
git:
url: https://gitlab+deploy-token-1:${DEPLOY_TOKEN}@************/my_private_package.git
现在,据我所知,pubspec 无法以这种方式解析 DEPLOY_TOKEN
环境变量。 pub get
完成时出错:
Git error. Command: `git clone --mirror https://gitlab+deploy-token-1:******@*******/my_private_package.git /Users/***/Library/flutter/.pub-cache/git/cache/my_private_package***`
stdout:
stderr: Cloning into bare repository '/Users/***/Library/flutter/.pub-cache/git/cache/my_private_package***'...
remote: HTTP Basic: Access denied
remote: You must use a personal access token with 'read_repository' or 'write_repository' scope for Git over HTTP.
remote: You can generate one at https://*****/-/profile/personal_access_tokens
fatal: Authentication failed for 'https://gitlab.*****/my_private_package.git/'
exit code: 128
我也尝试使用上面错误消息中提到的个人访问令牌,但得到了相同的结果。尽管如果指定了 git clone https://gitlab+deploy-token-1:${DEPLOY_TOKEN}@*******/my_private_package.git
环境变量,命令行中的 DEPLOY_TOKEN
可以正常工作。
我的问题:是否可以直接从 pubspec.yaml
使用环境变量?如果没有,我如何从另一台(不是 gitlab runner)CI 机器获取我的私有包?