I have an Azure Function App already created and I want to deploy a python function with Azure DevOps pipeline. The issue is that the pipeline runs without errors but the function is not created. Instead, in the App Files of the Function App, I see that in the wwwroot
folder there is the ImpervaWAFCloudSentinelConn
folder with all its contents as well as a default host.json
.
Here is the pipeline I run:
trigger:
- none
resources:
- repo: self
variables:
azureSubscription: "<my-service-connection>"
functionAppName: "<my-function-app-name>"
resourceGroupName: "<my-rg>"
stages:
- stage: Build
displayName: Build Function App
jobs:
- job: Build
displayName: Build Code
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.8'
addToPath: true
architecture: 'x64'
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./src/ImpervaWAFCloudSentinelConn/requirements.txt
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/src/ImpervaWAFCloudSentinelConn'
archiveFile: '$(Build.ArtifactStagingDirectory)/build$(Build.BuildId).zip'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/build$(Build.BuildId).zip'
artifactName: drop
- stage: Deploy
displayName: Deploy Code to Function App
jobs:
- job: Deploy
displayName: Deploy Code to Function App
pool: DevOps VMSS Agents
steps:
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: drop
targetPath: $(System.DefaultWorkingDirectory)
- task: AzureFunctionApp@2
inputs:
connectedServiceNameARM: $(azureSubscription) # string. Alias: azureSubscription. Required. Azure Resource Manager connection.
appType: 'functionAppLinux' # Required. App type.
appName: $(functionAppName) # Required. Azure Functions App name.
resourceGroupName: $(resourceGroupName)
package: '$(System.DefaultWorkingDirectory)/**/*.zip'
runtimeStack: 'PYTHON|3.8'
deploymentMethod: 'runFromPackage'
The application that I’m trying to deploy on the function app is the one mentioned in the documentation here.
The file structure of the git repository is the following:
- pipelines/
-- azure-pipelines-src.yaml
- src/
-- ImpervaWAFCloudSentinelConn/
--- host.json
--- proxies.json
--- requirements.txt
--- ImpervaWAFCloudSentinelConnector/
---- __init__.py
---- function.json
---- state_manager.py
2
Answers
If I have the following file structure:
What I need to do is to create a deployment slot in the Function App and deploy it there. In the end you have to swap with the default slot.
Here is the pipeline that worked for me:
I tried to deploy the Function from this Imperva Cloud ARM template and the url mentioned in this ARM template for the Function Trigger code files does not contain local.settings.json file, Thus it is causing the Function app to not read the function. As local.settings.json file is necessary for the Function app deployment even if it contains local settings. You can download the Function code from the URL and add local.settings.json in the root level Refer below:-
local.settings.json:-
Make sure you add a storage account Connection string in AzureWebJobsStorage
My Function code locally with below format:-
I sent this code to Azure repository and deployed the Function via Azure DevOps pipeline like below:-
My Azure DevOps repository:-
Selected below option:-
Output:-
Function is visible and got deployed successfully like below:-