问题
Our projects is currently using VSTS (Visual Studio Team Services) packages for sharing packages between projects. We want to adopt the Release Views feature to pick up packages at different stages of maturity for automated releases to different environments.
While it is pretty easy to promote a package to a specific view, I have not found a way to unpromote the package from that view. This could be needed for a couple of reasons:
- Package was promoted by mistake.
- Package needs to be unpromoted because of some issues found and thus needing to demote it to a lower maturity level.
I did not find a direct way of doing it via the VSTS user interface. I did find some articles of doing it via REST APIs, but looks like the current APIs under the Feeds don't support this any more.
Does anyone know how to achieve this?
回答1:
For now, there is no way to unpromoted packages in VSTS package management.
And I posted an user voice Enable to unpromote package in VSTS package management and update REST API document, which suggests to add the feature to unpromote packages and update the REST API document. You can vote and follow up.
And the REST API to promote a NuGet package as below:
PATCH https://{account}.pkgs.visualstudio.com/DefaultCollection/_apis/packaging/feeds/{feedId}/nuget/packages/{packageId}/versions/{packageVersion}?api-version=5.0-preview.1
application/json:
{
"views":
{ "op":"add",
"path":"/views/-",
"value":"release view" }
}
Note:
- For
feedId
andpackageId
in request URL, you can use feed name and package name instead. - For REST API versions, you can also use the older version like
3.0-preview.1
.
As below example to promote nuget package ConsoleApp1
with version 1.5.0-alpha
in new feed for pre
view, the REST API is (response with 202 Accepted state if success):
And use the PowerShell to achieve the example, and script can be:
$releaseViewURL = "https://marinaliu.pkgs.visualstudio.com/DefaultCollection/_apis/packaging/feeds/new/nuget/packages/ConsoleApp1/versions/1.5.0-alpha?api-version=5.0-preview.1"
$json = '
{
"views":
{ "op":"add",
"path":"/views/-",
"value":"pre" }
}
'
$bodyJson=$json | ConvertFrom-Json
$user="name"
$token="p1tjzehdq6tilwfjdbgbkymo3f3ojszmrlfgzh302fww6kgwnavq"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$response = Invoke-RestMethod -Uri $releaseViewURL -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ContentType "application/json" -Method Patch -Body $bodyJson
来源:https://stackoverflow.com/questions/51471803/vsts-unpromote-a-package-version-from-release-view