azure - 使用 azure devops 构建流水线
问题描述
我正在尝试使用 azure devops 为我的颤振应用程序创建构建管道。
我使用来自 Aloïs Deniel 的 azure 扩展来实现颤振。flutter install 任务成功通过。Flutter 构建挂起并在无限循环中抛出以下错误:
stderr: Cloning into bare repository '/Users/runner/hostedtoolcache/Flutter/1.26.0-1.0.pre-dev/macos/flutter/.pub-cache/git/cache/app_alh_packages-384b2d81da8d887d80ab6f47deedece96035bf0c'...
fatal: could not read Username for 'https://jointhedartsidewehavewidgets.visualstudio.com': terminal prompts disabled
exit code: 128
pub get failed (server unavailable) -- attempting retry 1 in 1 second...
我的 azure pipeline.yaml 文件非常简单:
variables:
projectDirectory: 'cleanedBloc'
trigger:
- main
pool:
vmImage: 'macos-latest'
steps:
- task: FlutterInstall@0
inputs:
channel: 'dev'
version: 'latest'
- task: FlutterBuild@0
inputs:
target: 'ios'
projectDirectory: $(projectDirectory)
我很高兴得到帮助。提前致谢。
解决方案
看起来颤振构建任务正在尝试从https://jointhedartsidewehavewidgets.visualstudio.com
. 由于云构建代理没有此 git 存储库的凭据。它会抛出上述错误。
您可以查看以下解决方法来解决此问题。
1,在您的 pubspec.yaml 文件中定义的 git url 中添加 git repo 凭据。见下文:
name: FlutterProject
environment:
sdk: ">=2.0.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: 0.1.2
Yourpackage:
git:
url: https://user_name:password@jointhedartsidewehavewidgets.visualstudio.com/yourProject/_git/yourRepo
ref: master
或者,您可以将个人访问令牌与Code read scope
凭据一起使用。
Yourpackage:
git:
url: https://{Personal Access Token}@jointhedartsidewehavewidgets.visualstudio.com/yourProject/_git/yourRepo
ref: master
如果您不想在 pubspec.yaml 文件中公开您的个人访问令牌。您可以创建一个管道秘密变量来保存 PAT。并添加替换令牌任务以将 PAT 添加到 pubspec.yaml 文件中。
请参见下面的示例:更改您的 pubspec.yaml 如下:
Yourpackage:
git:
url: https://#{token}#@jointhedartsidewehavewidgets.visualstudio.com/yourProject/_git/yourRepo
ref: master
在管道中定义一个秘密变量。
添加替换令牌任务以用#{token}#
PAT 替换。
- task: qetza.replacetokens.replacetokens-task.replacetokens@3
displayName: 'Replace tokens in pubspec.yaml'
inputs:
targetFiles: pubspec.yaml
- task: FlutterInstall@0
推荐阅读
- php - 与日期相关的 PHP 错误
- python - 如何在 Nameko 的依赖提供程序中使用 Config?
- python - 如何同时配置 django server 和 react server 到 AWS elastic beanstalk 服务
- java - 如何根据字符串数组中出现的单词对地图进行排序
- java - 即使设置了 serialVersionUID,反序列化也会引发 InvalidClassException
- python - 朴素贝叶斯分类器和训练数据
- javascript - Javascript | 拼接从数组中删除错误的项目
- javascript - 如何在 JavaScript 中编写一个函数来比较由 TreeNodes a 和 b 定义的两棵树?
- python - 合并两个 countvectorizer 时出现 isnan 错误
- symfony - 在外部 js 文件中使用 Twig 变量