Set Connection References and Environment Variables in Pipelines
Posted On 2021-12-02 • 8 min read
Since Microsoft has released both Connection References and Environment Variables the process of setting them in a Pipeline wasn’t very straightforward. Scott Durow (Twitter & LinkedIn) explained a possible solution to it in one of his blog posts (Connection References with ALM – Mind the Gap!). In this blog post, I will explain a different way to set Connection References and Environment Variables in Pipelines.
The approach I am explaining and demonstrating is as of writing (2021-12-01) still in preview.
Update: As of 2021-12-15 the explained approach is GA. See MS announcement.
Since parts of the approach are still in preview you would use it at your own risk. I personally figure this still might be better than handling everything manually, but more about that later.
First of all, we should talk a bit about the problems that we currently have when it comes to ALM and Connection References as well as Environment Variables.
When you are doing manual deployments it should work pretty well most of the time. When you import a solution that contains either Connection References you don’t have associated with a connection or Environment Variables where neither a default value nor current value exists an additional step in the import will be shown where you can configure those things.
Bigger problems arise when it comes to automated deployments. Since there isn’t a human interaction possible no one could associate connections to connection references or assign values to environment variables.
This means those things have to happen after the deployment is finished. Either manually or through some PowerShell Scripting (some might call it “voodoo”) as Scott describes in the mentioned blog.
A result is that all Power Automate flows using a connection reference without an associated connection will get inactivated during import.
Don’t get me wrong, I do like the idea of both of them. The problem was/is “only” the ALM part.
Fortunately, Microsoft listens to feedback and comes to the rescue. The Import Solution Task of the Power Platform Build Tools does have two new configurations UseDeploymentSettingsFile and DeploymentSettingsFile.
What you have to do is basically create a settings file where you map Environment Variables to values and Connection References to in your target environment already existing connections.
The step will then perform the assigning and association part itself. This should lead to smooth deployments including activated flows.
Let’s see how we could use this part of the Import Solution task.
To be able to follow this blog post we need to make sure we have some prerequisites in place.
I will base my explanation on the Basic ALM process I explained in an earlier blog post.
To summarize it very shortly:
The mentioned Basic ALM process does contain 3 build/release pipelines
Create export from DEV
Build Managed Solution
Release (to Test)
During the further explanations within this blog post, we will do changes in the last two of those pipelines.
What you can see is that there is an array of Environment Variables where you could add the desired value. The file also contains an array of Connection References, what missing here is the ID of the connection (in the target environment) you would like to associate.
For the ease of this post, I will hard code all of that. For sure you could dynamically set/fill this file as a part of your pipeline. What I found most practical is having a settings file for every target environment. Much like the app.config one knows from C# projects.
If you have several static settings files those have to be handled manually in the future. For example when new Environment Variables or Connection References should be added.
We have to change the following two things in this pipeline.
As the penultimate task in our pipeline, we add a “copy file” task.
As “Source Folder” we select the folder in our repository where we stored the settings file(s).
As “Contents” we write two stars (**) to fetch everything.
As “Target Folder” choose the artefact staging directory and “Settings” as the subfolder
Publish Pipeline Artifacts
We also have to alter the last task (Publish Pipeline Artifacts) in a way that takes the whole staging folder and not only the solution zip file.
To do so just change “File or directory path” to the following.
Release to Test
All that is left to set Connection References and Environment Variables in Pipelines is to change our Release to Test release pipeline to actually use the settings file.
To do so we check the checkbox “Use deployment settings file” and choose the correct file from the artifact.
As you can see this approach to set Connection References and Environment Variables in Pipelines is much easier than running different PowerShell scripts. That’s at least what I think. As mentioned this part of the import step is still in preview, but hopefully, it will be GA soon. Since 2021-12-15 this approach is GA and can safely be used in Production.
I hope this post helped you to come a bit closer to your ALM goal. Please feel free to contact me if you have any further questions.
This is just 1 of 52 articles. You can browse through all of them by going to the main page. Another possibility is to view the categories page to find more related content. You can also subscribe and get new blog posts emailed to you directly.
Privacy & Cookies Policy
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.