Azure devops 如何在azure pipelines for cd中捕获和保留通用工件的工件包版本
我有这个使用yaml的azure devops ci/cd管道。我的yaml有两个阶段CI和CD。我的CI阶段有一个名为BuildandDeploy的作业。CD阶段有一个部署作业。我正在使用通用工件来发布和下载相同的内容。在CD阶段,我使用Azure devops 如何在azure pipelines for cd中捕获和保留通用工件的工件包版本,azure-devops,azure-pipelines,continuous-delivery,Azure Devops,Azure Pipelines,Continuous Delivery,我有这个使用yaml的azure devops ci/cd管道。我的yaml有两个阶段CI和CD。我的CI阶段有一个名为BuildandDeploy的作业。CD阶段有一个部署作业。我正在使用通用工件来发布和下载相同的内容。在CD阶段,我使用UniversalPackagesdevops任务下载工件。该任务有一个名为vstsPackageVersion的输入变量,它是在通用工件中显示的包版本。我知道另外两个变量可以使用$(Build.BuildId)和$(Build.BuildNumber)。作为
UniversalPackages
devops任务下载工件。该任务有一个名为vstsPackageVersion的输入变量,它是在通用工件中显示的包版本。我知道另外两个变量可以使用$(Build.BuildId)
和$(Build.BuildNumber)
。作为一项临时工作,我正在为通用工件硬编码包版本
我无法下载带有两个内置变量的工件。由于CI和CD位于同一管道中,是否有任何方法来存储和检索工件的包版本?是否有像latest
这样的标识符,我可以使用它从universal package获取最新的工件
# specific branch build with batching
trigger:
batch: true
branches:
include:
- master
stages:
- stage: CI
jobs:
- job: BuildAndPublish
pool:
vmImage: 'Ubuntu-16.04'
steps:
-
script: |
docker build -t $(dockerId).azurecr.io/$(imageName):$(version) .
docker login -u $(dockerId) -p $(pswd) $(dockerId).azurecr.io
docker push $(dockerId).azurecr.io/$(imageName):$(version)
- task: Bash@3
displayName: Initialize Helm Client - create local repo
inputs:
targetType: 'inline'
script: '
helm init --client-only
'
- task: HelmDeploy@0
displayName: Package helm chart
inputs:
connectionType: 'Kubernetes Service Connection'
command: 'package'
chartPath: 'my-helm-dir'
- task: UniversalPackages@0
displayName: Publish helm package to my-company-artifacts
inputs:
command: 'publish'
publishDirectory: '$(Build.ArtifactStagingDirectory)'
feedsToUsePublish: 'internal'
vstsFeedPublish: '$(my-feed-guid)'
vstsFeedPackagePublish: 'my-artifact-name'
versionOption: patch
packagePublishDescription: 'My helm package descrition'
- stage: CD
jobs:
- deployment: DeployJob
displayName: Deploy Job
pool:
vmImage: Ubuntu-16.04
environment: dev
strategy:
runOnce:
deploy:
steps:
- task: UniversalPackages@0
displayName: 'Universal download'
inputs:
command: download
vstsFeed: '$(my-feed-name)'
vstsFeedPackage: 'my-artifact-name'
vstsPackageVersion: 0.0.32
- task: ExtractFiles@1
displayName: 'Extract files '
inputs:
archiveFilePatterns: '*.tgz'
destinationFolder: 'my-folder'
cleanDestinationFolder: true
基于
az Universal
cli的Universal Packages任务不支持“最新版本”,只支持特定版本(顺便说一句,此cli正在预览中)
作为解决方法,您可以使用RESTAPI检索最新版本并设置新变量,然后在下载任务中使用此变量
例如,添加获取版本号并设置变量的PowerShell任务:
- powershell: |
$head = @{ Authorization = "Bearer $env:TOKEN" }
$url = "https://feeds.dev.azure.com/{organization}/_apis/packaging/Feeds/{feed-name}/packages/{package-guid}?api-version=5.0-preview.1"
$package = Invoke-RestMethod -Uri $url -Method Get -Headers $head -ContentType application/json
$latestVersion = ($package.versions.Where({ $_.isLatest -eq $True })).version
Write-Host "The latest version is $latestVersion"
Write-Host "##vso[task.setvariable variable=latestVersion]$latestVersion"
env:
TOKEN: $(system.accesstoken)
现在,在下载任务中使用它:
vstsPackageVersion: $(latestVersion)
为什么不发布构建工件而不是使用版本化的通用软件包?您需要从构建/部署过程之外访问工件吗?如您所见,它是作为通用工件发布的。我正在尝试下载相同的。我能够下载工件,问题是如何获得工件包版本。这并没有回答我的问题。