cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LarsCJensen
Advocate I
Advocate I

Updating environment variables via devops pipeline

In reference to Updating Environment Variables in Managed Solution in which @EricRegnier posts a solution to change environment variables during deployment through a devops pipeline. 
He posts the following shell script:

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"
}


However, I am having problems getting the shell script to work. 
I'm getting the following error:

Missing type name after '['.
I've replaced the GUID with the id of my environment variable and "value" with the new environment variable value.

I suppose I'm missing some important detail, but could anyone point me in the right direction?
4 REPLIES 4
capoaus75
Frequent Visitor

Hi @LarsCJensen in your post you said that @EricRegnier posted a solution to change environment variables during deployment through a devops pipeline. I had a look at the link you have posted but I cannot find any reference to the shell script. I am trying to update a Solution environment variable when I deploy to a different environment and I need some guidance on how to setup the script. Any help/link that would point me in the right direction would be much appreciated. Thanks

capoaus75
Frequent Visitor

I found the correct link to the Shell script Solved: How to update Environmental variables under soluti... - Power Platform Community (microsoft....
@EricRegnier if you don't mind could you please elaborate a bit more how to implement the PowerShell script task in the pipeline? Let's say I have an environment variable called "SPO Site" with a value of https://mytenancy.com/DEVsite and during the deployment to TEST I would like the environment variable to be updated to https://mytenancy.com/TESTsite. Could you please point me in the right direction on how to implement this? Thank you so much.

I've given up on the idea of using PowerShell. Instead I've turned to Wael Hamze's DevOps Power Tools: Power DevOps Tools - Visual Studio Marketplace
There is a build tool called 'Update Environment Variables', which allow you to do just what the title suggests, update environment variables. 

Add this action after the import action and you should be all set. The build tool allows you to define environment variables and their updated values. 

capoaus75
Frequent Visitor

Thank you @LarsCJensen looks like a very useful tool, but I am not sure our Security Team will allow us to use it. I will give it a go on my personal tenancy. Reading at this post Announcing data source environment variables | Microsoft Power Apps they mention that New build tasks will be available soon for working with connection references and environment variables. That may solve the problem.

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.

Users online (3,218)