简体   繁体   English

flutter 使用 azure devops 构建管道

[英]flutter build pipeline with azure devops

i'm trying to create a build pipeline for my flutter app using azure devops.我正在尝试使用 azure devops 为我的 flutter 应用程序创建构建管道。

I use the azure extension for flutter from Aloïs Deniel.我使用 Aloïs Deniel 的 flutter 的 azure 扩展。 The flutter install task passes successfully. flutter 安装任务成功通过。 The Flutter build hangs and throws the following error in an infinite loop: 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...

My azure pipeline.yaml file is quite simple:我的 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)

I am happy to receive help.我很高兴得到帮助。 Thanks in advance.提前致谢。

It looks like the flutter build task was trying to download a azure git dependency from https://jointhedartsidewehavewidgets.visualstudio.com . It looks like the flutter build task was trying to download a azure git dependency from https://jointhedartsidewehavewidgets.visualstudio.com . Since the cloud build agent doesnot have the credentials for this git repo.由于云构建代理没有此 git 存储库的凭据。 It would throw out above error.它会抛出上述错误。

You can check about below workarounds to fix this issue.您可以查看以下解决方法来解决此问题。

1, Add the git repo credentials in git url which is defined in your pubspec.yaml file. 1,在 git url 中添加 git 回购凭证,该凭证在您的 pubspec.Z6EEDC273A68AF22DC733 文件中定义。 See below:见下文:

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      

Or you can use Personal access token with Code read scope for the credential.或者,您可以使用带有Code read scope个人访问令牌作为凭证。

Yourpackage:
         git: 
           url: https://{Personal Access Token}@jointhedartsidewehavewidgets.visualstudio.com/yourProject/_git/yourRepo
           ref: master  

If you didnot want to expose your Personal Access token in the pubspec.yaml file.如果您不想在 pubspec.yaml 文件中公开您的个人访问令牌。 You can create a pipeline secret variable to hold the PAT.您可以创建一个管道秘密变量来保存 PAT。 And add a replace token task to add the PAT to the pubspec.yaml file.并添加替换令牌任务以将 PAT 添加到 pubspec.yaml 文件中。

See below example: Change your pubspec.yaml as below:请参见下面的示例:更改您的 pubspec.yaml 如下:

 Yourpackage:
             git: 
               url: https://#{token}#@jointhedartsidewehavewidgets.visualstudio.com/yourProject/_git/yourRepo
               ref: master

Define a secret variable in your pipeline.在管道中定义一个秘密变量

在此处输入图像描述

Add replace token task to replace the #{token}# with the PAT.添加替换令牌任务以将#{token}#替换为 PAT。

- task: qetza.replacetokens.replacetokens-task.replacetokens@3
  displayName: 'Replace tokens in pubspec.yaml'
  inputs:
    targetFiles: pubspec.yaml   

- task: FlutterInstall@0  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM