Update your Azure DevOps REST API URLs after moving your organization under dev.azure.com

Update your URL for your organization

In the settings for your organization you can update your URL from {organization}.visualstudio.com to dev.azure.com/{organization}. Of course once you do this some of the environment variables used by Build and Release will change and if you took a dependency on their format things will break.

Failing PowerShell task

We happened to have a PowerShell script named Set-PackageQuality.ps1 in a release pipeline which had some code that parsed the URL from the SYSTEM_TEAMFOUNDATIONSERVERURI environment variable (see snippet below). I also submitted a pull request to René van Osnabrugge of Xpirit who authored the original script to help anyone else who may run into this in the future.

#global variables
$account = ($env:SYSTEM_TEAMFOUNDATIONSERVERURI -replace "https://(.*)\.visualstudio\.com/", '$1').split('.')[0]
$basepackageurl = ("https://{0}.pkgs.visualstudio.com/DefaultCollection/_apis/packaging/feeds" -f $account)

The code above was not able to parse the URL correctly after we updated our organization URL settings and our REST API call failed. Previously the value loaded into the environment was as follows:

[SYSTEM_TEAMFOUNDATIONSERVERURI] --> [https://like10.vsrm.visualstudio.com/]

After we updated our organization settings the URL was now in the new format:

[SYSTEM_TEAMFOUNDATIONSERVERURI] --> [https://vsrm.dev.azure.com/like10/]

Now at this point I figured I may as well update all references to the REST API to the new URL So I dove into the REST API documentation to find the proper URL to be using after moving our organization to the new URL so I could update the PowerShell script accordingly.

This is the change I made, you’ll notice I also changed the environment variable used to get the organization name as well as the base packaging URL for the REST API.

#global variables
$organization = ($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI -replace "https://dev\.azure\.com/(.*)/", '$1').split('.')[0]
$basepackageurl = ("https://pkgs.dev.azure.com/{0}/_apis/packaging/feeds" -f $organization)

I also updated the api-version parameter in the script to specify the latest version of the API

#API URL is slightly different for npm vs. nuget...
"npm" { $releaseViewURL = "$basepackageurl/$feedName/npm/$packageId/versions/$($packageVersion)?api-version=5.1-preview.1" }
"nuget" { $releaseViewURL = "$basepackageurl/$feedName/nuget/packages/$packageId/versions/$($packageVersion)?api-version=5.1-preview.1" }
default { $releaseViewURL = "$basepackageurl/$feedName/nuget/packages/$packageId/versions/$($packageVersion)?api-version=5.1-preview.1" }

The Set-PackageQuality.ps1 script is now executing properly in our Azure Release Pipeline.

PowerShell Task Set-PackageQuality.ps1

Hope this helps someone, I forgot about this dependency until the task failed 🙂

About Wes MacDonald

Wes MacDonald is a DevOps Consultant for LIKE 10 INC., a DevOps consulting firm providing premium support, guidance and services for Azure, Microsoft 365 and Azure DevOps.

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: