This article aims to patch one annoying gap in Microsoft’s documentation: how, exactly, do you update Azure Function App’s application settings using an Azure DevOps build/release pipeline? It sounds easy, and like something that should happen almost automatically – and for Azure Web Apps (or App Services, as they are often called) it IS practically automatic.
But for Azure Functions it isn’t. And the docs aren’t perfect. Let me try and fix that.
Azure Functions won’t take your appsettings.json file, “mapping” your variable groups or creating pipeline variables doesn’t do anything, and Azure DevOps doesn’t even provide a task for “managing application settings” or whatever.
But the solution is fairly simple, nonetheless.
There’s actually an optional parameter available for the Azure Functions deployment task – let’s see how to configure and use it!
Time needed: 10 minutes.
How to update application settings of Azure Functions using AzDO?
- (Optional) Configure your variable group
Add your desired app settings as variables. Remember the name of your variable group, you’ll need it later!
Alternatively, you can just define your variables as pipeline variables. But using the variable groups is often easier for centralized management, and because of the Azure Key Vault integration.
- (Optional) “Import” your Azure DevOps variable group to your pipeline
There’s probably a better word for this – but you can “import” or “reference” your variable groups from a lot of tasks on Azure DevOps using a syntax like shown below:
This’ll enable your task to use the variables like they were defined as build pipeline variables – which is really neat!
If you’re not using variable groups (i.e. you skipped the first step too and simple defined pipeline variables), you can skip this one as well.
- Add a task that supports appSettings transformation
Okay – so this is one step that could easily go wrong, as the way application settings are updated for Azure Functions is quite a bit different as opposed to an App Service or IIS website deployment.
Instead of enabling XML/JSON transformations or some other neat and semi-automatic way of replacing application setting, you’ll need to the properties that are to be overwritten to variables one by one – and you need to select the right task for the job!
Aaaaand the right task is called [email protected]. A little bit underwhelming, I know – but the real beef comes next…
- Insert the following (which looks very redundant, but works, I assure you)
One of the inputs this task accepts is called “appSettings.” You can overwrite appsettings one by one – like follows:
task: [email protected]
appSettings: '-CosmosDbConnectionString $(CosmosDbConnectionString)'
Yes – in this configuration, we’re overwriting an application setting called “CosmosDbConnectionString” with whatever value comes from a variable in the mapped variable group (imported in step 2), or in the pipeline variable (takes precedence).
You can obviously add multiple overwrites, and you don’t have to use variables – but most of the time you probably will want to!
That’s it! Now you know another thing that’s not properly documented anywhere online.
Here’s a more complex YAML sample for your copy-pasting use:
trigger: - main variables: - name: serviceconnection value: 'my service connection' stages: - stage: AzureFunctions dependsOn: pool: vmImage: 'windows-latest' jobs: - job: Build_AzureFunctions # omitted for clarity # deploy to Azure Web App dev/staging - job: DeployToDev variables: - group: Development.AzureFunctions dependsOn: Build_AzureFunctions condition: succeeded() pool: vmImage: 'windows-latest' steps: - download: current artifact: drop_af # Deployment to Azure Functions - task: [email protected] inputs: azureSubscription: $(serviceconnection) appType: functionApp appName: 'my-functions' package: $(Pipeline.Workspace)/**/$(AzureFunctionsName).zip appSettings: '-EventHubConnectionAppSetting $(EventHubConnectionAppSetting) -CosmosDbConnectionString $(CosmosDbConnectionString) -AzureSignalRConnectionString $(AzureSignalRConnectionString)'
Hint – in case you’re wondering how to access these application settings / properties in your Azure Functions code, see this article for details!
- A fantastic example of an extremely snobby and unhelpful Stack Overflow discussion regarding a similar issue.
- This article is offered as a solution in the link above – and doesn’t help at all. And to be fair, why would it? It’s about file/xml/JSON transformations, which are how this task can be done in other contexts, just not with Azure Functions
- I saw a sample of this somewhere on docs.microsoft.com, and it lead me to the solution, but I then lost the tab :(
- HttpContext.WebSockets.IsWebSocketRequest always null in .NET Core? - July 27, 2021
- Docker-compose fails on Windows with “Error while fetching server API version: (2, ‘CreateFile’, ‘The system cannot find the file specified.’)” - July 20, 2021
- Azure DevOps suddenly 404s for your project? Easy fix! - July 13, 2021