[英]Using YAML pipeline to deploy Azure Function
I'm trying to build and deploy an Azure Function using YAML pipelines.我正在尝试使用 YAML 管道构建和部署 Azure Function。 The build and publish stage works fine, it produces a zip file which I can download.
构建和发布阶段工作正常,它生成一个 zip 文件,我可以下载它。 However my deployment stage keeps failing with the following error: No package found with specified pattern: D:\a\1\drop\output.zip
但是我的部署阶段一直失败并出现以下错误:没有找到具有指定模式的 package:D:\a\1\drop\output.zip
I've tried using different environment variables and back/forward slash in the path.我试过在路径中使用不同的环境变量和后/前斜杠。
Note, that the vmImageName is set to 'windows-latest'请注意,vmImageName 设置为“windows-latest”
Output of the deployment stage:部署阶段Output:
What am I missing?我错过了什么?
Build and publish stage:构建和发布阶段:
- stage: Build
displayName: Build solution
jobs:
- job: Build
displayName: Build and publish solution
pool:
vmImage: $(vmImageName)
workspace:
clean: all
steps:
- checkout: self
- checkout: AzureUtil
- task: DotNetCoreCLI@2
displayName: Build and Publish Azure Function
inputs:
command: publish
arguments: '--configuration Release --output publish_output'
projects: $(projectsPath)/$(projectFileName)
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
- task: ArchiveFiles@2
displayName: "Archive files"
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)/publish_output"
includeRootFolder: false
replaceExistingArchive: true
archiveFile: $(Build.ArtifactStagingDirectory)\output.zip'
- task: PublishBuildArtifacts@1
displayName: "Publish build artifacts"
inputs:
PathtoPublish: $(Build.ArtifactStagingDirectory)\output.zip'
artifactName: 'drop'
Deployment stage:部署阶段:
- stage: Deploy
displayName: Deploy Azure Function
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy Azure Function
pool:
vmImage: $(vmImageName)
environment: 'Web-Dev'
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(serviceConnectionName)'
appType: functionApp
appName: '$(azureFunctionName)'
package: '$(Pipeline.Workspace)\drop\output.zip'
I tried to Deploy Azure Function to Function app via YAML pipeline and it was successful.我尝试通过 YAML 管道将 Azure Function 部署到 Function 应用程序,它成功了。
Created a.Net Http Trigger in my Visual studio pushed the Code to Azure Devops Repository and used default YAML pipeline below:-在我的 Visual Studio 中创建了一个 .Net Http 触发器,将代码推送到 Azure Devops 存储库,并使用下面的默认 YAML 管道:-
Azure DevOps Repository:- Azure DevOps 存储库:-
Default Pipeline:-默认管道:-
YAML pipeline code below referred from this Github link :- YAML 以下管道代码来自此Github 链接:-
# .NET Core Function App to Windows on Azure # Build a .NET Core function app and deploy it to Azure as a Windows function App. # Add steps that analyze code, save build artifacts, deploy, and more: # https://docs.microsoft.com/en-us/azure/devops/pipelines/languages/do.net-core trigger: - master variables: # Azure Resource Manager connection created during pipeline creation azureSubscription: 'xxxx-xxx-xxx-98e7-e2dxxxxx' # Function app name functionAppName: 'siliconfunc43' # Agent VM image name vmImageName: 'windows-2019' # Working Directory workingDirectory: '$(System.DefaultWorkingDirectory)/FunctionApp8' stages: - stage: Build displayName: Build stage jobs: - job: Build displayName: Build pool: vmImage: $(vmImageName) steps: - task: DotNetCoreCLI@2 displayName: Build inputs: command: 'build' projects: | $(workingDirectory)/*.csproj arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration Release - task: ArchiveFiles@2 displayName: 'Archive files' inputs: rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output' includeRootFolder: false archiveType: zip archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip replaceExistingArchive: true - publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip artifact: drop - stage: Deploy displayName: Deploy stage dependsOn: Build condition: succeeded() jobs: - deployment: Deploy displayName: Deploy environment: 'development' pool: vmImage: $(vmImageName) strategy: runOnce: deploy: steps: - task: AzureFunctionApp@1 displayName: 'Azure functions app deploy' inputs: azureSubscription: '$(azureSubscription)' appType: functionApp appName: $(functionAppName) package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
In the last step add:-在最后一步添加:-
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
Output:- Output:-
Function got deployed and triggered successfully, Refer below:- Function 已部署并成功触发,请参考以下内容:-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.