Skip to main content

Notifications

Power Platform Community / Forums / Design & Build / Deploying Environment ...
Design & Build
Answered

Deploying Environment Variables in a managed solution using Power Platform Pipeline

Posted on by 52
I've been struggling with this issue for some time now. Environment Variables are generally a good idea to create flexible solutions, but boy, are they tricky when used in a managed solution, deployed by a Power Platform Pipeline. So far the ONLY way that works for me is this:
 
  1. Create EV in solution on the DEV environment
  2. Set "Current Value" to a value appropriate for the DEV environment
  3. Before EACH (!!!) deployment, REMOVE the value of each EV. (I forgot this today and now I'm in trouble, see below...)
  4. After deleting the values, deploy the solution to the managed target environment
  5. During deployment, you'll be asked to specify the value (appropriate to the target environment)
  6. Complete deployment afterwards
  7. Go to 2. (Set "Current Value"...) and continue with the next development iteration
This works. But constantly SETTING the values and then REMOVING them again before deploying is cumbersome and dangerous. And wouldn't you know it, today I forgot to remove the values and deployed the solution as is. That worked, but of course the EV values were incorrect. No big deal, I thought, I'll simply re-deploy the solution with the usual step of removing the values. But nope, whenever I try to deploy the solution now, I get this weird error "Cannot insert duplicate key in object 'dbo.EnvironmentVariableValueBase'". I tried different steps, removing the EVs from the solution - deployment fails "Object reference not set to an instance of an object"). Setting the existing EV values on the target environment manually (using the trick with the Default solution, which lets me change EVs outside of the managed solution) then try re-deploying. But that didn't help either.

I'm stuck! It seems having forgot to remove the values killed my chances of re-deploying the solution. Luckily, the target environment is only a TEST environment and scrapping the whole solution will not be a disaster - but soon we will deploy to a production environment and I'm almost certain, that one day I will forget to remove the EV variables again during a rushed deployment and may become stuck again. Scrapping the whole solution won't be possible then. There HAS to be an easier and less dangerous way of using EVs in managed solutions!

A blog post suggested that EVs shouldn't be part of a managed solution at all, instead the should be in their own unmanaged solution and deployed separately to the target environment. I'll experiment with the idea for sure, but I'm also a little doubtful it will work...

Is there a rock-solid Best Practice for this? 
Categories:
  • Verified answer
    Flury Profile Picture
    Flury 52 on at
    Deploying Environment Variables in a managed solution using Power Platform Pipeline
    Resolution to this bug according to a MS support rep: 

    When a solution is marked as "preferred solution", apparently this bug sometimes appears: Your environment variables default to "Yes" and can't be turned off either. However, on the same environment, if you quickly create a temporary second solution and mark it as "preferred solution", then you should be able to change the slider to "No" and it will also stay "No" once you mark the solution again as preferred solution. 
     
  • Flury Profile Picture
    Flury 52 on at
    Deploying Environment Variables in a managed solution using Power Platform Pipeline
    I should also mention: I'm aware that below the Current value setting, there is a slider "Export Value". However, probably due to a current bug, this slider can't be changed! I will jump back to "export" when saving the EV setting. I can't see anyone mentioning this yet, so it must be a recent bug...

    EDIT: A MS support rep is helping me look into this. The problem with the slider seems to be specific to my solution. Even creating a new temporary solution on the same environment didn't have the same issue. So if the slider "Export Value" is by default in the "No" position, this is good news of course. It means, I should be able to simply leave my DEV EV current values in place and still get asked to provide new values during the deployment - without manually removing the values each time. Fingers crossed.

Helpful resources

Quick Links

Welcome to the Power Platform…

We are thrilled to unveil the newly-launched Power Platform Communities!…

Community Update 9/9/24…

Power Platform Community Update…

Welcome to the new Power Platform Community!…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 140,690

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,355

Leaderboard

Featured topics