我正在尝试使用 azure devops 为我的 Flutter 应用程序创建构建管道。
我使用 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)
我很高兴得到帮助。提前致谢。
答案 0 :(得分:2)
看起来 flutter 构建任务试图从 https://jointhedartsidewehavewidgets.visualstudio.com
下载一个 azure git 依赖项。由于云构建代理没有此 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
或者您可以使用 Personal access token 和 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
在您的管道中定义一个 secret variable。
添加 replace token task 以将 #{token}#
替换为 PAT。
- task: qetza.replacetokens.replacetokens-task.replacetokens@3
displayName: 'Replace tokens in pubspec.yaml'
inputs:
targetFiles: pubspec.yaml
- task: FlutterInstall@0