cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SivaGanesh
Regular Visitor

How to update Environmental variables under solutions from Azure DevOps tools

Hi,

 

I created environment variables of data source type to connect to SharePoint List and used it to create a Canvas APP. I wanted to push this solution to Prod by changing the Environment variables to Prod data sources. I am leveraging Power Platform Build Tools in Azure DevOps pipeline to deploy solutions into different environments but couldn't able to find a way to update those environment variables before pushing managed solution to Prod.

 

Could someone help me resolve this?

Any help is highly appreciated.

2 ACCEPTED SOLUTIONS

Accepted Solutions
ChrisPiasecki
Dual Super User
Dual Super User

Hi @SivaGanesh,

 

A blog announcement today mentioned that new build tasks will be available for managing environment variables in your deployment pipelines. I am not sure when this will become available, but there are also new APIs available to interact programmatically which you could use from a build script. It says the API documentation is in the process of being published so hopefully in the next couple of days this will be available.

 

Alternatively, if you don't want to wait, the Power DevOps Tools is another popular and open source extension for Azure DevOps which has a comprehensive list of tasks available, including Update Environment Variables.

 

---
Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

View solution in original post

EricRegnier
Super User
Super User

Hi @SivaGanesh,

As @ChrisPiasecki mentioned, not possible up to now but coming soon. The only way is with PowerShell script task in your pipeline. Here's a sample:

function Update-EnvVariable (
    [Guid] $EnvVariableId,
    [Microsoft.Xrm.Tooling.Connector.CrmServiceClient] $Connection
) {
    $updateFields = @{ }
    $updateFields.Add("value", $Value)  
    Set-CrmRecord -conn $Connection -Fields $updateFields -Id $EnvVariableId -EntityLogicalName "environmentvariablevalue"
}

Hope this helps!

View solution in original post

9 REPLIES 9
ChrisPiasecki
Dual Super User
Dual Super User

Hi @SivaGanesh,

 

A blog announcement today mentioned that new build tasks will be available for managing environment variables in your deployment pipelines. I am not sure when this will become available, but there are also new APIs available to interact programmatically which you could use from a build script. It says the API documentation is in the process of being published so hopefully in the next couple of days this will be available.

 

Alternatively, if you don't want to wait, the Power DevOps Tools is another popular and open source extension for Azure DevOps which has a comprehensive list of tasks available, including Update Environment Variables.

 

---
Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

EricRegnier
Super User
Super User

Hi @SivaGanesh,

As @ChrisPiasecki mentioned, not possible up to now but coming soon. The only way is with PowerShell script task in your pipeline. Here's a sample:

function Update-EnvVariable (
    [Guid] $EnvVariableId,
    [Microsoft.Xrm.Tooling.Connector.CrmServiceClient] $Connection
) {
    $updateFields = @{ }
    $updateFields.Add("value", $Value)  
    Set-CrmRecord -conn $Connection -Fields $updateFields -Id $EnvVariableId -EntityLogicalName "environmentvariablevalue"
}

Hope this helps!

It works. Thanks a ton for the help.

@SivaGanesh could you elaborate on how you got this to work?

DCSAlan
Frequent Visitor

Hi @EricRegnier, This is slightly off topic but is it possible to retrieve the Id of an Environment Variable Value from the name of the Environment Variable itself so I don't have to hard-code an ID in my pipeline?

 

Thanks

 

Alan

DCSAlan
Frequent Visitor

Managed to get there myself in the end, at least this seems to work

$evDefinition = Get-CrmRecords -conn $conn -EntityLogicalName environmentvariabledefinition -FilterAttribute "schemaname" -FilterOperator "eq" -FilterValue $evName
$evValue = Get-CrmRecords -conn $conn -EntityLogicalName environmentvariablevalue -FilterAttribute environmentvariabledefinitionid -FilterOperator "eq" -FilterValue $evDefinition.CrmRecords[0].environmentvariabledefinitionid
$newValues = @{}
$newValues.Add("value", $Value)
Set-CrmRecord -conn $conn -Fields $newValues -id $evValue.CrmRecords[0].environmentvariablevalueid -EntityLogicalName environmentvariablevalue

Hi @DCSAlan, sorry for my late reply. Just checked your PowerShell script and confirm that how to do it,  nice one! 

Teju123456
Regular Visitor

Hi, I am working on Pipeline to build and deploy solution from one source environment to destination environment.
I have one development environment where I am developing my power app and one other production  environment where importing solution.
I have created environment variables for SharePoint list in solution of development environment and also created build pipeline.
I found below environmentvariablesvalues.json file in repo.Test.png

What should I put in  $EnvVariableId,$Connection variables?

function Update-EnvVariable (
[Guid] $EnvVariableId,
[Microsoft.Xrm.Tooling.Connector.CrmServiceClient] $Connection
) {
$updateFields = @{ }
$updateFields.Add("value", $Value)
Set-CrmRecord -conn $Connection -Fields $updateFields -Id $EnvVariableId -EntityLogicalName "environmentvariablevalue"
}

The $Connection is the connection object to Dataverse. Here's an example:

$SecurePassword = ConvertTo-SecureString 'pw123' -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ('name@email.com', $SecurePassword)

$Connection = Get-CrmConnection -OnLineType OAuth -OrganizationName 'orgname' -DeploymentRegion 'Oceania' -Credential $creds

 

$EnvVariableId is the GUID of the environment variable. You can find that in your dev environment via Advanced Find or in Maker Portal -> Dataverse -> Tables -> Envionment Varibales -> Data -> open the row and the Guid will be in the querystring
You can find more examples here: https://github.com/ericregnier/power-platform-powershell-helpers

Hope this helps!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Users online (1,537)