Push settings to App Configuration in Azure Pipeline
Martin Eriksson
Posted on December 4, 2023
Here is a small automation tip that could be beneficial when working with Azure App Configuration.
TL;DR
Details
Those of you who are familiar with Bicep know that defining application settings is pretty straightforward. You define it directly in the App Service resource or a child resource under the App Service resource.
With App Configuration, it's not as straightforward. You can't define or push application settings to an Azure App Configuration resource via Bicep.
You can work around this by pushing the application settings to an Azure App Configuration resource in your Azure Pipeline instead by using the task "AzureAppConfigurationPush@6".
The "AzureAppConfigurationPush@6" task uses a predefined JSON file where you set your application settings. These values are pushed to the App Configuration resource. However, in most cases, you want to utilize output from the Bicep deployment to populate your application settings.
To do this, you can use JSON variable substitution.
But before you can substitute variables in the JSON file, you need to retrieve the output from the Bicep deployment.
Let's say that you have an output in your Bicep code defined as the following:
output variableA string = 'someValue'
Then, you can expose that output in your Azure Pipeline by defining the "deploymentOutputs" input in the "AzureResourceGroupDeployment@2" task. Let's set it to "deploymentOutputs" for the sake of this example.
If you provision your infrastructure in a separate "job" from the one where you push your application settings, you need to set the "Bicep deployment outputs" as outputs of the job as well.
Here is an example that sets the value of "variableA" from "deploymentOutputs" to a job output variable called "variableA":
- script: echo "##vso[task.setvariable variable=variableA;isOutput=true;]"$(deploymentOutputs.variableA.value)""
name: OutputVariables
The next step is to pass the output variable from "JobA" to "JobB" where you are pushing the application settings to Azure App Configuration. Let's say that the JSON file that you want to perform "JSON variable substitution" on looks like this:
{
"root": {
"variableA": ""
}
}
This means that you need to define a variable in "JobB" called "root.variableA" and set the value of that variable based on the output variable from "JobA" like this:
- job: JobB
dependsOn: JobA
variables:
root.variableA: $[ dependencies.JobA.outputs['JobA.OutputVariables.variableA'] ]
After this, if you run the "FileTransform@2" task followed by the "AzureAppConfigurationPush@6" task, you should be able to see a key-value pair in your Azure App Configuration resource with key: "root:variableA" and value "someValue" after running the pipeline.
Posted on December 4, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.