How to deploy a folder and file into an Azure Function App by bicep pipeline?

Khalid Hajjouji 50 Reputation points
2025-05-20T07:50:47.82+00:00

I have an pipeline with a yaml and bicep file to deploy an Azure function app with a couple of functions. I would like to also deploy a folder and file to "D:\home\data". For example:"D:\home\data\mySolution\template.xml". How to do this?

This is my yaml file

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)'


This is my bicep file:

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
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Robert Filistovič 0 Reputation points
    2025-05-20T07:57:27.0833333+00:00

    tep-by-Step Approach

    1. Prepare Your Folder/Files

    Make sure your folder structure is available in your repository or as a build artifact:

    /mySolution/template.xml
    

    1. Modify Your Azure Pipeline YAML

    Add a step after your Bicep deployment that uploads the file using Kudu API (via curl or Invoke-RestMethod) or az webapp deployment command.

    Option A: Using az webapp deploy (simpler)

    - task: AzureCLI@2
      inputs:
        azureSubscription: '<Your Azure Service Connection>'
        scriptType: bash
        scriptLocation: inlineScript
        inlineScript: |
          az webapp deployment source config-zip \
            --resource-group <your-resource-group> \
            --name <your-function-app-name> \
            --src ./mySolution.zip
    

    You need to zip your mySolution folder first in the pipeline:

    - task: ArchiveFiles@2
      inputs:
        rootFolderOrFile: '$(Build.SourcesDirectory)/mySolution'
        includeRootFolder: false
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/mySolution.zip'
        replaceExistingArchive: true
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.