Azure DevOps 发布 Azure 函数不起作用

Azure DevOps Publish Azure Function not working

我正在尝试创建管道以便在 Azure 函数 中发布我的代码。为此,我使用以下内容作为参考:https://docs.microsoft.com/en-us/azure/azure-functions/functions-how-to-azure-devops?tabs=dotnet-core%2Cyaml%2Ccsharp
但是我收到以下错误:

Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.

经过一番努力,我得到了以下 Build Pipeline yaml(我注释了导致错误的代码):

trigger:
- none

pr:
- none

pool:
  vmImage: "windows-latest"

variables:
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  #output: "publish"
  #project: "*.csproj"
  solution: "**/*.sln"
  
steps:

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

#- task: DotNetCoreCLI@2
#  inputs:
#    command: publish
#    arguments: "--configuration $(buildConfiguration) --output $(output)"
#    projects: $(project)
#    publishWebProjects: false
#    modifyOutputPath: false
#    zipAfterPublish: false

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

- task: ArchiveFiles@2
  displayName: "Zip Files"
  inputs:
    rootFolderOrFile: "$(Build.ArtifactStagingDirectory)"
    includeRootFolder: false
    archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"
    artifactName: "drop"

生成以下工件: 包含

发布管道:

steps:
- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy'
  inputs:
    azureSubscription: '<SubscriptionName>'
    appType: functionApp
    appName: <FunctionApp Name>
    deploymentMethod: zipDeploy

发布管道的执行以成功结束 然而,Azure 上没有发布任何内容

你知道我错过了什么吗?

我相信您在这里错过了发布步骤,您只是在构建而不是发布。您拥有的 zip 文件看起来不正确,发布后您应该会得到一大堆 *.dll 文件

您注释掉的代码需要在构建步骤后 运行。在理想的流程中它应该是。

这应该是理想的流程。

  1. 指定所需的 .NET 版本
  2. 恢复 nuget 包
  3. Dotnet 构建
  4. Donet 发布
  5. 归档文件
  6. 发布工件(发布将来自该工件)

在发布管道中,您应该获取已发布的工件,然后部署到 Azure

建造

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: 'sdk'
    version: '6.0.x'

- task: DotNetCoreCLI@2
  displayName: Restore Packages
  inputs:
    command: restore
    projects: '**/*.csproj'

- script: |
    dotnet build --configuration Release
  workingDirectory: '<path-to-your-project-tobuild>'
  displayName: "Build"

- task: DotNetCoreCLI@2
  displayName: "Publish"
  inputs:
    command: publish
    arguments: '--configuration Release --output publish_output'
    projects: '<path-to-your-project-tobuild>'
    publishWebProjects: false
    modifyOutputPath: false
    zipAfterPublish: false

- task: ArchiveFiles@2
  displayName: "Archive files"
  inputs:
    rootFolderOrFile: "$(System.DefaultWorkingDirectory)/publish_output"
    includeRootFolder: false
    archiveFile: "$(System.DefaultWorkingDirectory)/build.zip"

- task: PublishBuildArtifacts@1
  displayName: "Publish Artifacts"
  inputs:
    PathtoPublish: '$(System.DefaultWorkingDirectory)/build.zip'
    artifactName: 'drop'

并在您的发布管道中

 - task: DownloadBuildArtifacts@0
        inputs:
          buildType: 'current'
          downloadType: 'single'
          artifactName: drop
          downloadPath: '$(System.ArtifactsDirectory)'

      - task: AzureRmWebAppDeployment@4
        inputs:
          ConnectionType: 'AzureRM'
          azureSubscription: '<your-sub>'
          appType: 'webApp'
          WebAppName: '<your-name>'
          packageForLinux: '$(System.ArtifactsDirectory)/**/*.zip'