Azure-devops-docs: How to promote packages in views programmatically?

Created on 2 Nov 2018  Â·  12Comments  Â·  Source: MicrosoftDocs/azure-devops-docs

On "Communicate package quality with release views" page: "You can also promote using REST APIs."
I can't find any information.
My workflow is quite simple, it just needs 4 views:

  • Stable
  • Latest
  • Preview
  • CI
    One package pushed to the feed must be followed by one (for CI) packages to 4 promotions (Stable packages must also be available in Latest, Preview and CI views).
    This doesn't seem "incredible", does it?

I found this VSTS task but it seems clearly outdated since even the urls are not the ones from "Azure DevOps".

The REST API, in version 5.0 preview as well as in version 4.1 doesn't seem to expose any API point to perform this (quite simple) operation.

Any help will be greatly appreciated.

Olivier


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 devopprod

Most helpful comment

Here's curl example:

curl --header 'Content-Type: application/json' -X PATCH --user your_user:your_pass \
https://pkgs.dev.azure.com/your_org/_apis/packaging/feeds/you_feed_id/upack/packages/apim/versions/you_pack_version?api-version=5.0-preview.1 \
--data '{"views": {"op": "add", "path": "/views/-", "value": "Prerelease"}}'

All 12 comments

The page Communicate package quality with release views pages does state You can also promote using REST APIs, without linking or hinting at a REST API, and I can't find one publicly available either.

There may be a workaround for this, however.

On the Azure DevOps Web UI, promoting a NuGet or NPM package version to a Azure Artifacts view triggers the following REST API call (shortened for reference; standard authentication applies):

POST https://pkgs.dev.azure.com/{organization}/_apis/packaging/feeds/{feedId}/{nuget|npm}/packagesBatch
Content-Type: application/json

{
  "data": {
    "viewId": "{viewId}"
  },
  "operation": 0,
  "packages": [{
    "id": "{packageName}",
    "version": "{packageVersion}",
    "protocolType": "{NuGet|Npm}"
  }]
}

This call returns a 202 Accepted response with no body.

Please keep in mind that API is not officially documented (I can't find anything about /packagesBatch here), and is therefore subject to breaking changes at any given time.

@bcrosnier, you're great!

Any hope to have a clear statement about the long term availability of this /packagesBatch?

Great find @bcrosnier ! Might be time to learn how to write my own extension.

Looks like our REST APIs, which we just took some time to more thoroughly document, fell off the web site recently. We'll get those back up ASAP.

@jerickmsft Can you post the url here when they are re-posted?

Hi all! I work on the content around Azure Artifacts (and actually, lucky for me, REST APIs as well), I wanted to reach out and find out a docs solution that would have helped you find a solution or made your life a little easier. Please reach out and let me know what would have helped in the docs and I'll look to make the change!

Sounds like we're good here :) let me know if there's anything we can do to help make your lives easier!

Here's curl example:

curl --header 'Content-Type: application/json' -X PATCH --user your_user:your_pass \
https://pkgs.dev.azure.com/your_org/_apis/packaging/feeds/you_feed_id/upack/packages/apim/versions/you_pack_version?api-version=5.0-preview.1 \
--data '{"views": {"op": "add", "path": "/views/-", "value": "Prerelease"}}'

The Promote package to Release View extension by Rene van Osnabrugge worked great for me in Azure DevOps.

Here's curl example:

curl --header 'Content-Type: application/json' -X PATCH --user your_user:your_pass \
https://pkgs.dev.azure.com/your_org/_apis/packaging/feeds/you_feed_id/upack/packages/apim/versions/you_pack_version?api-version=5.0-preview.1 \
--data '{"views": {"op": "add", "path": "/views/-", "value": "Prerelease"}}'

I'm using the same code and getting a 202 response but the view is not set. This used to work fine in TFS on premise but we recently upgraded to Azure DevOps on premise and it stopped working. Any idea why that could be?

Was this page helpful?
0 / 5 - 0 ratings