Showing results for 
Search instead for 
Did you mean: 
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?
Advocate I
Advocate I

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

Advocate I
Advocate I

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 and during the deployment to TEST I would like the environment variable to be updated to 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. 

Advocate I
Advocate I

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

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.


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 (2,200)