使用相对定义自动升级nuget packge [英] Automatically promote a nuget packge using a relese definition

查看:53
本文介绍了使用相对定义自动升级nuget packge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在onprem Azure DevOps(版本17.143.28621.4)中,是否有一种方法可以使用发布定义中的任务将nuget程序包从一个视图自动提升到另一个视图?

In onprem Azure DevOps (Version 17.143.28621.4) is there a way to automatically promote a nuget package from one view to another using a task in a release definition?

当我们触发构建版本时,伪像(即nuget包)经历两个阶段

When we trigger a release for a build, the artefacts (i.e. nuget packages) go through two stages

  1. 预发布:将包推送到供稿(在@Local视图中结束).
  2. 发布:应将软件包从@Local升级到@Release视图.
  1. PreRelease: The packages are pushed to the feed (ending up in the @Local view).
  2. Release: The packages should be promoted from the @Local to the @Release view.

不幸的是,阶段2当前是Azure DevOps Web UI中的手动步骤.可以通过版本定义将其自动化吗?

Unfortunately stage 2. is currently a manual step in the Azure DevOps web UI. Can it be automated via the release definition?

如果这不可能,是否有更好的方法来组织我们的发布管道和软件包供稿/视图,以使nuget软件包的发布完全自动化?

If this is not possible, is there a better way to organise our release pipeline and package feeds/views to make a release of nuget packages fully automatic?

推荐答案

您可以使用以下powershell脚本来推广多个软件包.该脚本假定所有软件包都具有相同的版本(一个产品由多个软件包组成).与我们的"DevOps Server 2019"配合使用时效果很好.

The following powershell script you can use to promote multiple packages. This script assumes that all packages have the same version (one product consisting of several packages). It is working fine with our "DevOps Server 2019".

param(
  [Parameter(Mandatory=$True)]
  [string]$tfsCollectionUri,
  [Parameter(Mandatory=$True)]
  [string]$feedName,
  [Parameter(Mandatory=$True)]
  [string]$packageVersion,
  [Parameter(Mandatory=$True)]
  [string]$packageQuality
)

$ErrorActionPreference = "Stop"

[regex]$nameExpression = "(?<name>[^0-9]*)\."
$json = '{ "views": { "op":"add", "path":"/views/-", "value":"' + $packageQuality + '" } }'
Write-Verbose -Message $json

Get-ChildItem . -Filter *.nupkg | Foreach-Object {
  $matches = $nameExpression.Match($_.Name)
  $packageName = $matches.groups['name']
  $requestUri = $tfsCollectionUri + "/_apis/packaging/feeds/$feedName/nuget/packages/$packageName/versions/$packageVersion" + "?api-version=5.0-preview.1"
  Write-Verbose -Message $requestUri
  $reponse = Invoke-RestMethod -Uri $requestUri -UseDefaultCredentials -ContentType "application/json" -Method Patch -Body $json
  Write-Verbose -Message "Response: '$reponse'"
}

参数 packageQuality 应为发布"或预发行",但不以"@"开头.

The parameter packageQuality should be e.g. "Release" or "Prerelease", without leading "@".

非常感谢 Shayki Abramczyk 为正确的方向提供了提示.

Many thanks to Shayki Abramczyk for the tip in the right direction.

这篇关于使用相对定义自动升级nuget packge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆