这是这个问题的转发,https://learn.microsoft.com/en-us/answers/questions/1462841/deploying-python-function-application-with-devops 添加到 SO 以获得更多观看次数。
使用 VS Code 并按照下面链接的 Microsoft 文章创建了 Python Azure 函数(模型 V2),并使用函数应用程序的默认代码。
使用下面链接的文章(已有几年历史)在 Azure DevOps 中设置了构建管道和发布管道。发布管道中的任务与文章不同,但其他一切似乎都进展顺利。
从当前可用的任务来看,“Azure Function Deploy”任务似乎是最好且唯一合适的。下面的屏幕截图显示了可用的任务。
当Release Pipeline运行时,运行成功。根据下面的屏幕截图,所有文件都已移动到功能应用程序服务。它运行了多次,编辑了默认的“function_app.py”文件中的注释,并添加了新文件以确保构建管道 + 部署管道正在移动文档。
但是,没有实际的函数在运行并且可以与之交互。 (参见下面的屏幕截图)。您知道部署管道中需要进行哪些修改才能使其正常工作吗?
我按照相同的文档创建了 python 函数应用程序,并通过 DevOps 管道部署它,它在我这边工作得很好。
请按照以下步骤进行检查:
我在创建函数应用程序时使用了 python 3.11,因此我在管道上指定了 3.11。我的yaml供您参考。
trigger: none
pool:
vmImage: ubuntu-latest
variables:
# Azure service connection established during pipeline creation
azureSubscription: YourAzureResourceServiceConnection
appName: functionappname
steps:
- task: UsePythonVersion@0
displayName: "Setting Python version to yours"
inputs:
versionSpec: '3.11'
addToPath: true
architecture: 'x64'
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --output ./bin
fi
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
- task: ArchiveFiles@2
displayName: "Archive files"
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
includeRootFolder: false
archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip'
artifactName: 'drop'
- task: AzureFunctionApp@2 # Add this at the end of your file
inputs:
azureSubscription: $(azureSubscription)
appType: functionAppLinux # default is functionApp
appName: $(appName)
package: $(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip
deploymentMethod: 'auto' # 'auto' | 'zipDeploy' | 'runFromPackage'. Required. Deployment method. Default: auto.