如何自动根据最新发布的NuGet设置预发行版NuGet的版本? [英] How to set version of the prerelease NuGet according to the latest released NuGet automatically?

查看:65
本文介绍了如何自动根据最新发布的NuGet设置预发行版NuGet的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个管道,release和prerelease.

I have two pipelines, release and prerelease.

在这样设置的发布管道版本中,为补丁程序计数器和手动设置主要/次要版本:

In release pipeline version set up like this, the counter for the patch and manually set major/minor version:

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  majorVersion: '1'  
  minorVersion: '1'
  patchVersion: $[counter(format('{0}.{1}', variables['majorVersion'], variables['minorVersion']), 0)]
  productVersion: $[format('{0}.{1}.{2}', variables['majorVersion'], variables['minorVersion'], variables['patchVersion'])]    

在预发布管道中,我手动检查最新发行版中所有主要版本,次要版本和修补程序的版本,我仅在最后添加Build.BuildNumber,以将其声明为预发布版本:

In prerelease pipeline I manual check what is the version for all major, minor and patch from the latest release, I only add Build.BuildNumber in the end to declare it as a prerelease:

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  majorVersion: '1'  
  minorVersion: '1'
  patchVersion: '2' <!-- if the last release patch version was 1, in the next prerelease I need here 2-->
  productVersionBeta: $[format('{0}.{1}.{2}-{3}', variables['majorVersion'], variables['minorVersion'], variables['patchVersion'], variables['Build.BuildNumber'])] 

最后,我打包并推动NuGet.

In the end I pack and push NuGet.

我希望在预发布管道中拥有的是:

What I would like to have in my prerelease pipeline is:

variables:
 solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

  majorVersion: $(SOMEHOW_GET_LATEST_MAJOR_RELEASE_VERSION) 
  minorVersion: $(SOMEHOW_GET_LATEST_MINOR_RELEASE_VERSION) 
  patchVersion: $(SOMEHOW_GET_LATEST_PATCH_RELEASE_VERSION) + 1

  productVersionBeta: $[format('{0}.{1}.{2}-{3}', variables['majorVersion'], variables['minorVersion'], variables['patchVersion'], variables['Build.BuildNumber'])]


是否有可能因为我没有发现任何有关Yaml config的描述而导致的行为?


Is it possible to get the behavior as described with only yaml config because I didn't find anything about it?

如果无法仅通过配置执行操作,那么我找到了此REST API

If it's not possible to do just through the config then I found this REST API The Artifact Details - Get Package Version. Is there a clean way to implement it inside the pipeline for the same purposes?

推荐答案

我认为这是不可能的,您需要使用REST API.请检查以下示例:

I think that this is not possible out of the box and you need to use REST API. Please check this example:

variables:
  orgName: 'thecodemanual'
  packageId: '8e0deb67-89bd-499f-ae8c-1d3814be540a'

steps:
    - pwsh: |
       
        $url = "https://feeds.dev.azure.com/$(orgName)/$(System.TeamProject)/_apis/packaging/Feeds/devops-manual/Packages/$(packageId)?api-version=6.0-preview.1"
        $packageInfo = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
        Write-Host "Pipeline = $($packageInfo | ConvertTo-Json -Depth 100)"

        $version = $packageInfo.versions[0].version

        Write-Host $version

        $sp = $version.Split(".")

        echo $sp

        $majorVersion = $sp[0]
        $minorVersion = $sp[1]
        $patchVersion = [int]$sp[2] + 1
        $productVersionBeta = "$majorVersion.$minorVersion.$patchVersion-$(Build.BuildNumber)"

        Write-Host "##vso[task.setvariable variable=packageVersion]$version"
        Write-Host "##vso[task.setvariable variable=majorVersion]$majorVersion"
        Write-Host "##vso[task.setvariable variable=minorVersion]$minorVersion"
        Write-Host "##vso[task.setvariable variable=patchVersion]$patchVersion"
        Write-Host "##vso[task.setvariable variable=productVersionBeta]$productVersionBeta"
      name: initial
    - pwsh: |
        Write-Host 'packageVersion: $(packageVersion)'
        Write-Host 'majorVersion: $(majorVersion)'
        Write-Host 'minorVersion: $(minorVersion)'
        Write-Host 'patchVersion: $(patchVersion)'
        Write-Host 'productVersionBeta: $(productVersionBeta)'

我的软件包的最新版本(我从此端点 https://feeds.dev.azure.com/{{organization}}/{{project}}/_apis获得了 packageId /packaging/Feeds/devops-manual/Packages?api-version=6.0-preview.1 )是 2.1.2 ,通过上述管道,我得到了以下值:

Latest version of my package (I got packageId from this endpoint https://feeds.dev.azure.com/{{organization}}/{{project}}/_apis/packaging/Feeds/devops-manual/Packages?api-version=6.0-preview.1) is 2.1.2 and with above pipeline I get these values:

packageVersion: 2.1.2
majorVersion: 2
minorVersion: 1
patchVersion: 3
productVersionBeta: 2.1.3-20200901.6

这篇关于如何自动根据最新发布的NuGet设置预发行版NuGet的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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