trigger: - main pool: vmImage: 'ubuntu-latest' variables: - group: MyVariableGroup stages: - stage: DeployInfrastructure displayName: 'Deploy Infrastructure' jobs: - job: Deploy displayName: 'Deploy Resources' steps: - task: AzureCLI@2 inputs: azureSubscription: $(azureServiceConnection) scriptType: 'bash' scriptLocation: 'inlineScript' inlineScript: | # Create resource group az group create --name $(resourceGroupName) --location $(location) # Create storage account az storage account create --name $(storageAccountName) --location $(location) --resource-group $(resourceGroupName) --sku Standard_LRS # Create Function App with Consumption Plan az functionapp create --consumption-plan-location $(location) --name $(functionAppName) --os-type Linux --resource-group $(resourceGroupName) --runtime python --runtime-version 3.11 --storage-account $(storageAccountName) - stage: DeployCode displayName: 'Deploy Code' dependsOn: DeployInfrastructure jobs: - job: Deploy displayName: 'Deploy Function App Code' steps: - checkout: self - task: UsePythonVersion@0 inputs: versionSpec: '3.11' addToPath: true - script: | python -m pip install --upgrade pip python -m venv .venv source .venv/bin/activate pip install -r requirements.txt displayName: 'Install dependencies' # Create a proper structure for the function app - script: | # Create the zip file with proper structure echo "Creating function app archive..." zip -r $(Build.ArtifactStagingDirectory)/functionapp.zip . ls -la $(Build.ArtifactStagingDirectory)/ displayName: 'Archive function app files' # Publish the artifact with a specific name - task: PublishPipelineArtifact@1 inputs: targetPath: '$(Build.ArtifactStagingDirectory)/functionapp.zip' artifact: 'functionapp' publishLocation: 'pipeline' displayName: 'Publish Function App Artifact' # Deploy using the AzureFunctionApp task which is better for Function Apps - task: AzureFunctionApp@1 inputs: azureSubscription: $(azureServiceConnection) appType: 'functionApp' appName: $(functionAppName) package: '$(Build.ArtifactStagingDirectory)/functionapp.zip' deploymentMethod: 'zipDeploy' displayName: 'Deploy Function App'