Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using service definition to obtain symbol service url #7822

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions Tasks/PublishSymbolsV2/PublishSymbols.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,38 @@ Trace-VstsEnteringInvocation $MyInvocation

$ErrorActionPreference = "Stop"

function Get-SymbolServiceUri ([string]$collectionUri)
{
$serviceDefinitionUri = "$collectionUri/_apis/servicedefinitions/locationservice2/951917ac-a960-4999-8464-e3f0aa25b381"
$result = Invoke-WebRequest $serviceDefinitionUri -UseBasicParsing

if ($result.StatusCode -eq 200) {
$locationUri = (ConvertFrom-Json $result.Content).locationMappings[0].location
if (-not $locationUri) {
throw "No location mappings found while querying $serviceDefinitionUri"
}
$locationServiceUri = "$locationUri/_apis/servicedefinitions/locationservice2/00000016-0000-8888-8000-000000000000"
$result = Invoke-WebRequest $locationServiceUri -UseBasicParsing
if ($result.StatusCode -ne 200) {
throw "Failure while querying '$locationServiceUri', returned $($result.StatusCode)"
}
$artifactsUri = (ConvertFrom-Json $result.Content).locationMappings[0].location
if (-not $artifactsUri) {
throw "No location mappings found while querying $artifactsUri"
}
Write-Host "Retrieved artifact service url: '$artifactsUri'"
}
else { # Fallback
if ( [RegEx]::Match($collectionUri, '\.(visualstudio\.com|vsts\.me)') ) {
$artifactsUri = [RegEx]::Replace($collectionUri, '\.(visualstudio\.com|vsts\.me)', '.artifacts.$1')
}
else {
$artifactsUri = [RegEx]::Replace($collectionUri, '://[^/]+/([^/]+)', '://$1.artifacts.visualstudio.com')
}
}
return $artifactsUri
}

try {
# Import the localized strings.
Import-VstsLocStrings "$PSScriptRoot\Task.json"
Expand Down Expand Up @@ -166,14 +198,7 @@ try {
throw "If PAT or UseAad is specified, then AccountName needs to be present"
}

[string]$SymbolServiceUri = (Get-VstsTaskVariable -Name 'System.TeamFoundationCollectionUri' -Require)

if (-not $SymbolServiceUri.Contains(".visualstudio.com")) {
$SymbolServiceUri = $SymbolServiceUri.Replace(".vsts.me",".artifacts.vsts.me") # Handle Devfabric scenario
}
else {
$SymbolServiceUri = $SymbolServiceUri.Replace(".visualstudio.com",".artifacts.visualstudio.com")
}
[string]$SymbolServiceUri = Get-SymbolServiceUri (Get-VstsTaskVariable -Name 'System.TeamFoundationCollectionUri' -Require)

$Endpoint = Get-VstsEndPoint -Name "SystemVssConnection"
[string]$PersonalAccessToken = $Endpoint.Auth.Parameters.AccessToken
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PublishSymbolsV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 8
"Patch": 9
},
"minimumAgentVersion": "1.95.0",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PublishSymbolsV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 8
"Patch": 9
},
"minimumAgentVersion": "1.95.0",
"groups": [
Expand Down