1

我有这个管道,它工作得很好,但是每次构建都非常耗时,在桌面 xcode 中,构建时间不到 5 分钟,在 mac 云服务器中,它需要 20
尤其是它下载的部分,在
“安装”中配置和编译本机 gem gems and cocoapods script”任务如下
,然后是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}}'
4

2 回答 2

1

您可以考虑并检查缓存 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
于 2020-10-01T08:30:44.153 回答
0

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

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

请参阅本文档中的 Microsoft 托管代理的功能和限制。如果您想安装和使用自托管代理,可以参考此文档

于 2020-10-14T03:23:20.850 回答