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
Super User
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 II
Super User II

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

7 REPLIES 7
ChrisPiasecki
Super User
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 II
Super User II

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

It works. Thanks a ton for the help.

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

DCSAlan
New Member

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
New Member

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! 

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,116)