-1

How to Promote npm packages in Azure DevOps feed view from @local to @pre-release to @release, through shell/python/PowerShell script?

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
Parminder Singh
  • 77
  • 2
  • 10
  • Hi friend, is there any update for this issue? Feel free to let me know if this issue is still blocking you :) – LoLance Apr 07 '20 at 09:32
  • @Lance Li-MSFT Thanks for asking Actually, I have tried the promote package tasks , but it will not work in my scenario. Because , I need to pass multiple packages with multiple versions in parameters. Also, we cannot do it with script because we don't want to pass token or credentials in a script , it should bring the token or credentials automatically. So I'm looking into customized promote task which should take multiple packages with multiple versions as a parameter – Parminder Singh Apr 07 '20 at 17:09

2 Answers2

0

You can try to write a script that does it with Azure DevOps Rest API, but there are two extensions that already did it:

1) Promote package to Release View

2) Promote

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
0

How to Promote npm packages in Azure DevOps feed view from @local to @pre-release to @release, through shell/python/PowerShell script?

As Shayki Abramczyk said above, there already exists extensions to do that job. But if you do want a working PS script, here's mine:

$token = "Enter your Pat here"

$url = "https://pkgs.dev.azure.com/OrgName/ProjectName/_apis/packaging/feeds/FeedID/npm/packagesbatch?api-version=5.1-preview.1"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$JSON = @'
{
  "data": {
    "viewId": "Release"
  },
  "operation": 0,
  "packages": [{
    "id": "YourPackageName",
    "version": "PackageVersion",
    "protocolType": "Npm"
  }]
}
'@

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -ContentType application/json -body $JSON

Note:

Enter your own PAT in $token, and replace the OrgName, ProjectName, FeedID, YourPackageName, PackageVersion with your own ones, you can set PreRelease/Release in viewID to promote npm packages in Azure DevOps feed view from @local to @pre-release to @release.

Update 1

If you want to run it in Linux environment using bash, try using this script:

curl --header 'Content-Type: application/json' -X Post --user PAT:xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
https://pkgs.dev.azure.com/YourOrgName/YourProjectName/_apis/packaging/feeds/YourFeedName/npm/packagesbatch?api-version=5.1-preview.1 \
--data '{ "data": {"viewId":"Release"},"operation": 0,"packages": [{"id": "YourPackageName","version": "YourPackageVersion","protocolType": "Npm"}]}'

To Generate PAT: https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page#create-a-pat

halfer
  • 19,824
  • 17
  • 99
  • 186
LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Thanks for the help Just want to know one more thing, Can we do this with SHELL script also ? – Parminder Singh Mar 20 '20 at 08:38
  • Hmm, see [this](https://github.com/MicrosoftDocs/vsts-docs/issues/2333#issuecomment-493663645), I think we can do this in shell script cause as I know bash can call curl command directly. But the syntax in shell script is different from that in powershell, so it may take some time to work on that. I'll come back when I can succeed to do that... – LoLance Mar 20 '20 at 09:04