I build Power Apps for my company. We leverage Multiple DEV environments, UAT environments and production environments as part of our platform governance. What environments are used depends on what the app is and whom it is for. We are also leveraging solutions to perform promotion from DEV->UAT->Production. We have been doing that for about 9 months or so, but all manually. Ugh, what a PITA and so time consuming.
As part of our Power App development we are also leveraging Azure Insights, so we have the Instrumentation key stored in the App object. There lies our problem, the Instrumentation key value cannot use a variable or code to set it. It is basically hardcoded in the App object. This presents a problem for us as we use different Azure Insights instances for each environment.
We are now in the process of introducing Azure DevOps into our deployment process. Eliminating the manual process we do now to move code from one environment to another.
So you are all caught up on what we have been up to...
We are building Pipelines to perform builds and promotion of our solutions.
Each Build Pipeline uses a Task group to create a new Build for a solution. The Task group has the following steps:
So the goal here is to export a solution as both managed and unmanaged, unpack it, and store all the unpacked code in the source repository.
Our goal is to store the source of the exported ZIP files in source control, not the actual ZIP files. When we deploy a Solution to another environment we repack the solution from the repository and import that packed solution.
So that is step one... COMPLETED
What I would like to do from here is to pack the code back into solutions but first update the InstrumentationKey then import the solution into the appropriate environment. I am looking for some advice on the best way to accomplish this. We have instrumentation keys for DEV, UAT and Prod. So we would need to use the same source repository and update the key, pack a solution, then do it again for prod. (This would be so much easier if Microsoft allowed the use of an environment variable, or a variable period, to set the key.) But short of that miracle, can anyone provide any advice on how best to accomplish what we need?
Thank in advance.
Steven
@sperry1625 Once you've unpacked the solution, use the powerapps CLI to unpack any apps in the solution (.msapp).
The instrumentation key is handily stored in a file called AppInsightsKey.json and looks something like:
{
"InstrumentationKey": "00000000-0000-0000-0000-000000000000"
}
You can then update it in the pipeline before packing up the app and then the solution
if (Test-Path -Path $AppPath\$AppName\AppInsightsKey.json -PathType Leaf) {
Write-Host "AppInsightsKey.json found"
((Get-Content -Path $AppPath\$AppName\AppInsightsKey.json -Raw) -replace "$(InstrumentationKey-Dev)","$(InstrumentationKey-Pre)") | Set-Content -Path $AppPath\$AppName\AppInsightsKey.json
}
There are multiple tasks available in devops to find and replace text in an file.
So when you deploy to an environment, before repacking the solution use a pipeline task to replace the instrumentation key with one you have in a devops variable and you are good to go.
One I frequentie use is replace tokens or magic chunks.
You should be able to achieve your requirements this way.
@TarunEY unfortunately we have not. I'm sure I could introduce a step in the Release pipeline that could update the key, I know exactly where it is stored, but I have not had the time, not the patience, to do it. So, for the moment I manually edit the application once deployed into the new environment and update the Instrumentation key. Not the most ideal solution, but it works, for now.
Regards,
-S
@sperry1625 Any solution or workaround for the issue? We have the same requirement.
WarrenBelz
81
Most Valuable Professional
mmbr1606
53
Super User 2025 Season 1
stampcoin
48