Automatically promote a nuget packge using a relese definition

前端 未结 2 1952
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 09:40

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?

<
相关标签:
2条回答
  • 2021-01-05 10:07

    Edit: Now I see you are with on-prem server so the extension will not work for you, so you must use the Update Package Version Rest API.

    Add a PowerShell task to execute the API, something like this (it's for update work item, just change the body and the URL to the correct Rest API):

    Don't forget to check the checkbox on the agent job options: Allow scripts to access the OAuth token.

    If you use Azure DevOps you can install the Promote package to Release View extension and add it to your pipeline:

    0 讨论(0)
  • 2021-01-05 10:14

    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'"
    }
    

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

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

    0 讨论(0)
提交回复
热议问题