Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Answered

Azure Devops - ALM - Retrieve Environment URL from Service Connection

(0) ShareShare
ReportReport
Posted on by 28

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!

  • smadep Profile Picture
    96 on at
    Re: Azure Devops - ALM - Retrieve Environment URL from Service Connection

    any chance to retrieve that env url (like Microsoft does it in WhoAmI task)

    smadep_0-1685435948616.png

    and use it tasks below? or set it like with the powershell task in recommended "solution" above?

  • Verified answer
    Dohsan Profile Picture
    28 on at
    Re: Azure Devops - ALM - Retrieve Environment URL from Service Connection

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 109 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 82 Super User 2025 Season 1

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 72

Overall leaderboard