首页 > 解决方案 > 使用 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)

我很高兴得到帮助。提前致谢。

标签: azureflutterdartbuildazure-pipelines

解决方案


看起来颤振构建任务正在尝试从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  

推荐阅读