發佈和下載組建成品

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

注意

建議您使用下載 管線成品發佈管線成品, 以提升效能。

Azure Artifacts 可讓小組使用摘要和上游來源來管理其相依性。 您可以使用 Azure Pipelines 發佈和下載不同類型的成品,作為 CI/CD 工作流程的一部分。

發佈成品

成品可以在管線的任何階段發佈。 您可以使用 YAML 或傳統 Azure DevOps 編輯器來發佈套件。

- powershell: gci env:* | sort-object name | Format-Table -AutoSize | Out-File $env:BUILD_ARTIFACTSTAGINGDIRECTORY/environment-variables.txt

- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop
  • pathToPublish:成品的路徑。 這可以是絕對路徑或相對路徑。 不支援通配符。
  • artifactName:成品的名稱。

注意

發行成品時,請確定您未使用其中一個保留的資料夾名稱。 如需詳細資訊,請參閱 應用程式資料夾

範例:使用多個工作

- powershell: gci env:* | sort-object name | Format-Table -AutoSize | Out-File $env:BUILD_ARTIFACTSTAGINGDIRECTORY/environment-variables.txt

- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop1
- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop2
  • pathToPublish:成品的路徑。 這可以是絕對路徑或相對路徑。 不支援通配符。
  • artifactName:成品的名稱。

範例:複製和發佈二進位檔

- powershell: gci env:* | sort-object name | Format-Table -AutoSize | Out-File $env:BUILD_ARTIFACTSTAGINGDIRECTORY/environment-variables.txt

- task: CopyFiles@2
  inputs:
    sourceFolder: '$(Build.SourcesDirectory)'
    contents: '**/$(BuildConfiguration)/**/?(*.exe|*.dll|*.pdb)'
    targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop
  • sourceFolder:包含您要複製之檔案的資料夾。 如果您將此保留空白,則會從 $(Build.SourcesDirectory)進行複製。
  • 內容:要包含在複本中的檔案路徑。
  • targetFolder:目的地資料夾。
  • pathToPublish:要發佈的資料夾或檔案路徑。 它可以是絕對路徑或相對路徑。 不支援通配符。
  • artifactName:您要建立之成品的名稱。

注意

請務必不要使用 artifactName 的保留名稱,例如 BinApp_Data。 如需詳細資訊,請參閱 ASP.NET Web 專案資料夾結構

下載成品

- powershell: gci env:* | sort-object name | Format-Table -AutoSize | Out-File $env:BUILD_ARTIFACTSTAGINGDIRECTORY/environment-variables.txt

- task: DownloadBuildArtifacts@0
  inputs:
    buildType: 'current'
    downloadType: 'single'
    artifactName: 'drop'
    downloadPath: '$(System.ArtifactsDirectory)'
  • buildType:指定要下載的組建成品: current (預設值)或從特定組建下載。
  • downloadType:選擇下載單一成品或特定組建的所有成品。
  • artifactName:將下載的成品名稱。
  • downloadPath:將下載成品之代理程式計算機上的路徑。

注意

如果您使用部署工作,您可以使用 $(Agent.BuildDirectory) 參考組建成品。 如需詳細資訊,請參閱 代理程式變數

當您的管線執行完成時,請流覽至 [ 摘要 ] 以探索或下載成品。

已發佈的組建成品

提示

  • 如果您使用 Azure DevOps Server 來允許使用個人存取令牌進行驗證,請停用 IIS 基本身份驗證。 如需詳細資訊,請參閱 IIS 基本身份驗證和 PAT

  • 在檔案路徑自變數中使用正斜線。 反斜杠無法在macOS/Linux代理程序中運作。

  • 組建成品會儲存在 Windows 檔系統上,這會導致所有 UNIX 許可權遺失,包括執行位。 從 Azure Pipelines 下載成品之後,您可能需要還原正確的 UNIX 許可權。

  • Build.ArtifactStagingDirectoryBuild.StagingDirectory 是可互換的。

  • Build.ArtifactStagingDirectory 每個組建之後都會清除path。

  • 刪除與發行至檔案共用之套件相關聯的組建,會導致刪除該 UNC 路徑中的所有成品。

  • 如果您要將套件發佈至檔案共用,請務必提供組建代理程式的存取權。

  • 如果您的組織使用防火牆,請確定您允許 Azure Artifacts 網域 URL 和 IP 位址