Hi Everyone
Looking for some help in retrieving the Environment URL from a service connection, when using the 'Power Platform Set Connection Variables' task.
Currently I have the following in my yaml file:
task: PowerPlatformSetConnectionVariables@2
displayName: 'Set Connection Variables'
name: connectionVariables
inputs:
authenticationType: 'PowerPlatformSPN'
PowerPlatformSPN: 'MyServiceConnectionName'
With this I am able to access the service connection's AppID/TenantID/Secret for use in my Powershell scripts with no issue, for example:
Add-PowerAppsAccount -TenantID '$(connectionVariables.BuildTools.TenantId)' -ApplicationId '$(connectionVariables.BuildTools.ApplicationId)' -ClientSecret '$(connectionVariables.BuildTools.ClientSecret)' -Endpoint "prod"
However, when accessing the variable connectionVariables.BuildTools.DataverseConnectionString it returns the following with the environment URL marked as undefined
AuthType=ClientSecret;url=undefined;ClientId=****...
By default it looks like the environment property on the 'Power Platform Set Connection Variables' task is set to $(BuildTools.EnvironmentUrl), which looking at the documentation is only populated on the pipeline when the 'Power Platform Create Environment' task is used (devops-build-tool-tasks#power-platform-create-environment )
So we've tried adding the Environment property onto the task, but still returns as undefined (hard coded example):
task: PowerPlatformSetConnectionVariables@2
displayName: 'Set Connection Variables'
name: connectionVariables
inputs:
authenticationType: 'PowerPlatformSPN'
PowerPlatformSPN: 'MyServiceConnectionName'
Environment: 'myenvironmenturl.crm.dynamics.com'
As a work around we can build the dataverse connection string in the Powershell script, but feels like this shouldn't be necessary given there's a variable on the pipeline for it.
Any insight much appreciated!
any chance to retrieve that env url (like Microsoft does it in WhoAmI task)
and use it tasks below? or set it like with the powershell task in recommended "solution" above?
Managed to find the fix/workaround for this. If you run a powershell task in your pipeline first, you can set the $(BuildTools.EnvironmentUrl)
task: PowerShell@2
displayName: "Set Service Connection Url"
inputs:
targetType: 'inline'
script: |
Write-Host "##vso[task.setvariable variable=BuildTools.EnvironmentUrl]${{'https://yourUrl.dynamics.com'}}"
The 'Power Platform Set Connection Variables' then picks this up by default and correctly sets the url on BuildTools.DataverseConnectionString
WarrenBelz
109
Most Valuable Professional
Michael E. Gernaey
82
Super User 2025 Season 1
MS.Ragavendar
72