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

标签 .net azure azure-devops yaml azure-pipelines

我的解决方案中有多个 .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 package mentioned in the task is published as an artifact in the build or a previous 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/

相关文章:

c# - 如何使用泛型的底层泛型类型 C#

java - 如何使用 Java 客户端将公共(public) IP 地址与 Azure 中的负载均衡器分离?

c# - Azure DevOps Pipeline 构建失败,因为它可以创建文件夹来写入 XML 文档文件

azure-devops - VSTS 发布批准电子邮件

.net - .NET for Universal Windows 程序是 .NET Core 的子集吗?

.net - 您可以使用 Roslyn 从语义符号转换回语法树节点吗?

c# - 悬停菜单项时更改背景颜色但无法在wpf中显示子菜单

azure - 将 200MB 文件上传到 Azure Blob 存储时出错

azure - 如何将我的 json 路径从 Azure 数据工厂映射到 cosmos db

azure-devops - Azure DevOps 仅存档来自构建删除的选定文件?