How to enable Application Insights in an deployed Azure Function app by bicep pipeline in Azure DevOps?
Khalid Hajjouji
50
Reputation points
How to enable logging in an deployed Azure Function app by bicep pipeline in Azure DevOps?
yaml:
trigger:
- none
pool:
vmImage: 'ubuntu-latest'
variables:
environment: 'prd'
location: 'West Europe'
functionAppName: 'az-func-app-test-$(environment)'
storageAccountName: 'teststorageaccount$(environment)'
resourceGroupName: 'rg-test-$(environment)-001'
appServicePlanName: 'test-appserviceplan-$(environment)'
serviceConnectionName: 'test PRD Azure Appregistratie'
stages:
- stage: Deploy_Infrastructure
displayName: 'Deploy Azure Function Infrastructure'
jobs:
- job: DeployBicep
steps:
- task: AzureCLI@2
inputs:
azureSubscription: $(serviceConnectionName)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az storage account create \
--name $(storageAccountName) \
--resource-group $(resourceGroupName) \
--location westeurope \
--sku Standard_RAGRS \
--kind StorageV2 \
--min-tls-version TLS1_2 \
--allow-blob-public-access false
az deployment group create \
--resource-group $(resourceGroupName) \
--template-file functionapp.bicep \
--parameters functionAppName=$(functionAppName) storageAccountName=$(storageAccountName) appServicePlanName=$(appServicePlanName) environment=$(environment)
- stage: Deploy_FunctionCode
displayName: 'Deploy Function Code'
dependsOn: Deploy_Infrastructure
jobs:
- job: DeployCode
steps:
- task: AzureFunctionApp@1
inputs:
azureSubscription: $(serviceConnectionName)
appType: 'functionApp'
appName: '$(functionAppName)'
package: '$(System.DefaultWorkingDirectory)'
bicep:
param location string = 'West Europe'
param functionAppName string
param storageAccountName string
param appServicePlanName string
param environment string
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-06-01' = {
name: storageAccountName
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
resource appServicePlan 'Microsoft.Web/serverfarms@2021-02-01' = {
name: appServicePlanName
location: location
sku: {
name: 'EP1' //Elastic Premium EP1
// 'Y1' //Consumption Plan
}
kind: 'functionapp'
}
resource functionApp 'Microsoft.Web/sites@2021-02-01' = {
name: functionAppName
location: location
kind: 'functionapp'
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: appServicePlan.id
siteConfig: {
appSettings: [
{ name: 'AzureWebJobsStorage', value: storageAccount.properties.primaryEndpoints.blob }
{ name: 'FUNCTIONS_WORKER_RUNTIME', value: 'powershell' }
{ name: 'APP_ENVIRONMENT', value: environment }
{ name: 'FUNCTIONS_EXTENSION_VERSION', value: 'latest' }
]
}
}
}
output functionAppName string = functionApp.name
Azure DevOps
431 questions
Sign in to answer