- Print
- Comment
- DarkLight
- PDF
Step 18 - Set Function Key Logic App - Build
Article summary
Did you find this summary helpful?
Thank you for your feedback!
In this task we want to take a variable from the pipeline and set it as a function key. We will then also set it as a parameter in the Logic App that it will use to call the functions.
To do this we will use the Azure CLI task with version 2 (preview) and set it to run a Powershell Script. The script will access Azure and use the API to setup a function key.
You can read more about setting up function keys - Click Here
The below picture shows you the configuration of this task:
YAML
Below is the yaml for this task
variables:
ARM_SUBSCRIPTION_ID: '[TBC]'
resourceGroupName: '[TBC]'
functionAppName: '[TBC]'
functionAppKey: '[TBC]'
steps:
- task: AzureCLI@2
displayName: 'Azure CLI - Set Function Key - Logic App'
inputs:
azureSubscription: '[TBC]'
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
$subscriptionId = "$(ARM_SUBSCRIPTION_ID)"
$resourceGroup = "$(resourceGroupName)"
$webAppName = "$(functionAppName)"
$functionKey = "$(functionAppKey)"
$keyName = "LogicApp"
$functionKey = $(functionAppKey)
az --version
az rest --help
$resourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.Web/sites/$webAppName"
Write-Host "Resource Id = " $resourceId
#List Keys
#=========
Write-Host 'Checking updated keys'
$output = az rest --method post --uri "$resourceId/host/default/listKeys?api-version=2018-11-01"
Write-Host $output
$LastExitCode
if (!$?) {
Write-Error "Error listing keys 1"
return
}
#Delete Existing key
#===================
Write-Host 'Deleting existing key'
$output = az rest --method delete --uri "$resourceId/host/default/functionkeys/$($keyName)?api-version=2018-11-01"
Write-Host $output
$LastExitCode
if (!$?) {
Write-Error "Error deleting key"
return
}
#Add new Key
#===========
$payload = (@{ properties=@{ name=$keyName; value="$functionKey" } } | ConvertTo-Json -Compress).Replace('"', '\"')
Write-Host "Payload = " $payload
Write-Host 'About to put new key in Azure'
$output = az rest --method put --uri "$resourceId/host/default/functionkeys/$($keyName)?api-version=2018-11-01" --body "$payload"
Write-Host $output
$LastExitCode
if (!$?) {
Write-Error "Error adding key"
return
}
#List Keys
#=========
Write-Host 'Checking updated keys'
$output = az rest --method post --uri "$resourceId/host/default/listKeys?api-version=2018-11-01"
Write-Host $output
$LastExitCode
if (!$?) {
Write-Error "Error listing keys 2"
return
}
powerShellErrorActionPreference: continue
addSpnToEnvironment: true
powerShellIgnoreLASTEXITCODE: true
continueOnError: true
Was this article helpful?