azure托管的Mac管道,关于如何使其更快目前非常慢的建议,在台式机上运行5分钟,在20点附近的服务器上

问题描述

我有这个管道,效果很好,但是在每次构建时都非常耗时 桌面版xcode只需不到5分钟即可构建,而在mac cloud服务器中则只需20分钟
特别是它下载的部分在
中配置和编译本机gem。 “安装宝石和cocoapods脚本”任务在下面
接下来是Fastlane任务:“ run fastlane”
编译部分很慢的地方...
我在寻找技巧和窍门,或者更好地组织我的渠道以加快构建速度

    pool:
      vmImage: 'macOS 10.14'
        
    variables:
      scheme: ''
      sdk: 'iphoneos'
      configuration: 'Release'
      
    jobs:
    - job: self_hosted_connect
      timeoutInMinutes: 10
      pool: Default
    
      steps:
        
      - task: copyFiles@2
        inputs:
          SourceFolder: '$(Agent.HomeDirectory)/../${{parameters.Folderpath}}'
          Contents: '**'
          TargetFolder: '$(build.artifactstagingdirectory)'
      - task: PublishBuildArtifacts@1
        inputs:
          pathToPublish: '$(build.artifactstagingdirectory)'
          artifactName: 'ios_artifacts'
    
    - job: mac_agent
      dependsOn: self_hosted_connect   
      timeoutInMinutes: 30
    
      pool:
        vmImage: 'macOS 10.14'
      steps:
      - script: echo 'Setting up macOS 10.14'
     
      - task: UseRubyVersion@0
        inputs:
         versionSpec: '>= 2.4'
         addToPath: true 
     
      - task: DownloadBuildArtifacts@0
        inputs:
          buildType: 'current'
          downloadType: 'single'
          artifactName: 'ios_artifacts'
          downloadpath: '$(System.ArtifactsDirectory)'  
      
      - script:  |
         
         gem install --no-document bundler
         bundle update --bundler
         bundle install --retry=3 --jobs=4 
         gem install --no-document fastlane
         pod deintegrate
         gem install cocoapods
         pod install    
         pod --version
         
        workingDirectory: '$(System.ArtifactsDirectory)/ios_artifacts'
        displayName: 'installing gems and cocoapods'
      
      - script:  |
         echo 'Start invoking Fastfile'
         fastlane release --verbose
         echo 'Done invoking Fastfile'
        failOnStderr: false 
        workingDirectory: '$(System.ArtifactsDirectory)/ios_artifacts'
        displayName: 'run fastlane'
      
      - task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: '$(Build.ArtifactStagingDirectory)'
          ArtifactName: 'Artifacts'
          publishLocation: 'Container'
          
    - job: copy_back_files_to_self_hosted_connect
      dependsOn: mac_agent 
      timeoutInMinutes: 30
      pool: Default
      steps:
        - task: DownloadBuildArtifacts@0
          inputs:
            buildType: 'current'
            downloadType: 'single'
            artifactName: 'Artifacts'
            itemPattern: | 
                    **/*.ipa
                    **/*manifest.plist*
            downloadpath: '$(System.ArtifactsDirectory)'
        - task: copyFiles@2
          inputs:
            SourceFolder: '$(System.ArtifactsDirectory)'
            Contents: | 
                    **/*.ipa
                    **/*manifest.plist*
            TargetFolder: '$(Agent.HomeDirectory)/../${{parameters.FolderCompile}}'

使用缓存更新

添加了缓存部分,但运行时却出现错误

 Resolving key:
2020-10-01T11:39:48.3151700Z  - gems       [string]
2020-10-01T11:39:48.3241700Z  - "Darwin"   [string]
2020-10-01T11:39:48.3720810Z  - my.gemspec [file] (not found)
2020-10-01T11:39:48.3882910Z ##[error]One or more errors occurred. (File not found: my.gemspec)
2020-10-01T11:39:48.4094600Z ##[section]Finishing: Cache gems




    

池: vmImage:'macOS 10.14'

variables:
  scheme: ''
  sdk: 'iphoneos'
  configuration: 'Release'
  BUNDLE_PATH: $(Pipeline.Workspace)/.bundle
  
jobs:
- job: self_hosted_connect
  timeoutInMinutes: 10
  pool: Default

  steps:
    
  - task: copyFiles@2
    inputs:
      SourceFolder: '$(Agent.HomeDirectory)/../${{parameters.Folderpath}}'
      Contents: '**'
      TargetFolder: '$(build.artifactstagingdirectory)'
  - task: PublishBuildArtifacts@1
    inputs:
      pathToPublish: '$(build.artifactstagingdirectory)'
      artifactName: 'ios_artifacts'

- job: mac_agent
  dependsOn: self_hosted_connect   
  timeoutInMinutes: 30

  pool:
    vmImage: 'macOS 10.14'
  steps:
  - script: echo 'Setting up macOS 10.14'
 
  - task: UseRubyVersion@0
    inputs:
     versionSpec: '>= 2.4'
     addToPath: true 
 
  - task: DownloadBuildArtifacts@0
    inputs:
      buildType: 'current'
      downloadType: 'single'
      artifactName: 'ios_artifacts'
      downloadpath: '$(System.ArtifactsDirectory)'  
  
  - task: Cache@2
    inputs:
       key: 'gems | "$(Agent.OS)" | my.gemspec'
       restoreKeys: | 
        gems | "$(Agent.OS)"
        gems
       path: $(BUNDLE_PATH)
    displayName: Cache gems
  
  - script:  |
     
     gem install --no-document bundler
     bundle update --bundler
     bundle install --retry=3 --jobs=4 
     gem install --no-document fastlane    
     
    workingDirectory: '$(System.ArtifactsDirectory)/ios_artifacts'
    displayName: 'installing gems and cocoapods'
 
 - script:  |
     pod deintegrate      
     gem install cocoapods     
     pod install      
     pod --version
    workingDirectory: '$(System.ArtifactsDirectory)/ios_artifacts'
    displayName: 'pod and cocoapods install '
  
  - script:  |
     echo 'Start invoking Fastfile'
     fastlane release --verbose
     echo 'Done invoking Fastfile'
    failOnStderr: false 
    workingDirectory: '$(System.ArtifactsDirectory)/ios_artifacts'
    displayName: 'run fastlane'
  
  - task: PublishBuildArtifacts@1
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)'
      ArtifactName: 'Artifacts'
      publishLocation: 'Container'
      
- job: copy_back_files_to_self_hosted_connect
  dependsOn: mac_agent 
  timeoutInMinutes: 30
  pool: Default
  steps:
    - task: DownloadBuildArtifacts@0
      inputs:
        buildType: 'current'
        downloadType: 'single'
        artifactName: 'Artifacts'
        itemPattern: | 
                **/*.ipa
                **/*manifest.plist*
        downloadpath: '$(System.ArtifactsDirectory)'
    - task: copyFiles@2
      inputs:
        SourceFolder: '$(System.ArtifactsDirectory)'
        Contents: | 
                **/*.ipa
                **/*manifest.plist*
        TargetFolder: '$(Agent.HomeDirectory)/../${{parameters.FolderCompile}}'

解决方法

您可以考虑并检查here所示的缓存gem:

variables:
  BUNDLE_PATH: $(Pipeline.Workspace)/.bundle

steps:
- task: Cache@2
  inputs:
    key: 'gems | "$(Agent.OS)" | my.gemspec'
    restoreKeys: | 
      gems | "$(Agent.OS)"
      gems
    path: $(BUNDLE_PATH)
  displayName: Cache gems

- script: bundle install
,

您可以尝试使用自托管代理而不是Microsoft托管代理。

  • 在Microsoft托管的代理中,每次运行管道时,都会得到一个 新鲜的虚拟机。一台虚拟机被丢弃 使用。
  • 在自托管代理中,计算机级缓存和配置持续存在 从头到尾运行,可以提高速度。

请参阅this document中Microsoft托管代理的功能和限制。 如果要安装和使用自托管代理,可以参考this document