gpt4 book ai didi

.net - 无法使用 pipeline.yml 文件部署 azure 函数应用程序

转载 作者:行者123 更新时间:2023-12-03 07:00:05 25 4
gpt4 key购买 nike

我的解决方案中有多个 .net mvc 应用程序和 1 个 .net azure function 应用程序。我有一个用于部署的 azure-pipeline.yml 文件。 Mvc 应用程序转到应用程序服务,Function 应用程序转到 azure 函数。

现在,当我在 azure devops 上运行管道时,它会将 webapps 部署到相应的应用程序服务,但无法部署 azure 函数并出现错误:

##[error]Error: No package found with specified pattern: D:\a\1\a**\FunctionApp.zip
Check if the packagementioned in the task is published as an artifact in the build or aprevious stage and downloaded in the current job. Finishing:AzureFunctionApp

但我可以在构建工件中看到 FunctionApp.zip。

这是我的 yml:

trigger:
- master
- feature/*
- hotfix/*

pool:
vmImage: 'windows-2019'

variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
isMaster: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]
isDeployableBranch: $[eq(variables.isMaster, true)]

stages:
- stage: Build
displayName: Build and Test Package
jobs:
- job: Build_Test_Publish
displayName: Build_Test_Publish
steps:
- task: NuGetToolInstaller@1

- task: VisualStudioTestPlatformInstaller@1
displayName: 'Install Visual Studio Test Platform'
inputs:
packageFeedSelector: 'nugetOrg'
versionSelector: 'latestStable'

- task: NuGetCommand@2
displayName: 'Restore NuGet packages'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: 'config'
nugetConfigPath: './'
externalFeedCredentials: 'Telerik NuGet'

- task: VSBuild@1
displayName: 'Build Solution'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=$(isDeployableBranch) /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'

- task: VSTest@2
displayName: 'Run Unit Tests'
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
condition: and(succeeded(), eq(variables.isDeployableBranch, true))
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'


- stage: Deploy
displayName: Deploy
condition: and(succeeded(), eq(variables.isDeployableBranch, true))
jobs:
- deployment: DeployWebApp1
displayName: Deploy Web App 1
environment: 'PROD'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'

- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'MyResourcegroup'
appType: 'webApp'
WebAppName: 'webapp1'
packageForLinux: '$(System.ArtifactsDirectory)/**/WebApp1.zip'

- deployment: DeployWebApp2
displayName: Deploy Web App 2
environment: 'PROD'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'

- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'MyResourceGroup'
appType: 'webApp'
WebAppName: 'webapp2-motionkinetic'
packageForLinux: '$(System.ArtifactsDirectory)/**/WebApp2.zip'


- deployment: DeployFunction
displayName: Deploy Function
environment: 'PROD'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'

- task: AzureFunctionApp@1
inputs:
azureSubscription: 'MyResourceGroup'
appType: functionApp
appName: 'MyFunction'
package: '$(System.ArtifactsDirectory)/**/FunctionApp.zip'

我认为问题出在 yml 文件本身。我做错了什么?

最佳答案

更新:

trigger:
- main

pool:
vmImage: 'windows-latest'


stages:
- stage: C
displayName: C
jobs:
- job: xxx
displayName: xxxOfC
steps:
- task: VSBuild@1
inputs:
solution: '**\*.sln'
- task: CmdLine@2
inputs:
script: |
mkdir AF
mkdir MVC1
mkdir MVC2
- task: CopyFiles@2
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/FunctionAppAndMVC/bin/Debug/netcoreapp3.1'
Contents: '**'
TargetFolder: '$(System.DefaultWorkingDirectory)/AF'
displayName: Copy Files to AF
- task: CopyFiles@2
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/MVC1/bin/Debug/netcoreapp3.1'
Contents: '**'
TargetFolder: '$(System.DefaultWorkingDirectory)/MVC1'
displayName: Copy Files to MVC1(1)
- task: CopyFiles@2
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/MVC1/wwwroot'
Contents: '**'
TargetFolder: '$(System.DefaultWorkingDirectory)/MVC1'
displayName: Copy Files to MVC1(2)
- task: CopyFiles@2
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/MVC2/bin/Debug/netcoreapp3.1'
Contents: '**'
TargetFolder: '$(System.DefaultWorkingDirectory)/MVC2'
displayName: Copy Files to MVC2(1)
- task: CopyFiles@2
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/MVC2/wwwroot'
Contents: '**'
TargetFolder: '$(System.DefaultWorkingDirectory)/MVC2'
displayName: Copy Files to MVC2(2)

- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/AF'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/FunctionApp.zip'
replaceExistingArchive: true
displayName: Archive Azure Function Files
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/MVC1'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/MVC1.zip'
replaceExistingArchive: true
displayName: Archive MVC1 Files
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/MVC2'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/MVC2.zip'
replaceExistingArchive: true
displayName: Archive MVC2 Files

- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
displayName: Publish Artifact
- stage: D
displayName: Deploy
jobs:
- job: xxx
displayName: xxxOfD
steps:
- task: DownloadBuildArtifacts@1
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'
- task: AzureFunctionApp@1
inputs:
azureSubscription: 'testbowman_in_AAD'
appType: 'functionApp'
appName: 'testbowman'
package: '$(System.ArtifactsDirectory)/drop/AF.zip'
deploymentMethod: 'auto'
- task: AzureWebApp@1
inputs:
azureSubscription: 'xxx'
appType: 'webApp'
appName: 'xxx'
package: '$(System.ArtifactsDirectory)/drop/MVC1.zip'
deploymentMethod: 'auto'
- task: AzureWebApp@1
inputs:
azureSubscription: 'xxx'
appType: 'webApp'
appName: 'xxx'
package: '$(System.ArtifactsDirectory)/drop/MVC2.zip'
deploymentMethod: 'auto'

原始答案:

在部署阶段之前我没有看到 FunctionApp.zip。

似乎没有人将文件存档为“FunctionApp.zip”(从您的 YAML 中我看不到它)。

下面的 YAML 可以工作:

trigger:
- main

pool:
vmImage: 'windows-latest'

stages:
- stage: C
displayName: C
jobs:
- job: xxx
displayName: xxxOfC
steps:
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/FunctionApp.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- stage: D
displayName: Deploy
jobs:
- job: xxx
displayName: xxxOfD
steps:
- task: DownloadBuildArtifacts@1
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'
- task: AzureFunctionApp@1
inputs:
azureSubscription: 'testbowman_in_AAD'
appType: 'functionApp'
appName: 'testbowman'
package: '$(System.ArtifactsDirectory)/**/*.zip'
deploymentMethod: 'auto'

关于.net - 无法使用 pipeline.yml 文件部署 azure 函数应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72533382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com