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
Helper I
Helper 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

capoaus75
Helper I
Helper 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 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
Helper I
Helper 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

Announcements
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.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (1,370)