.net - 如何从 Devops 管道将 azure 函数发布到 Active Directory 中的 Azure Linux 函数

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

我正在尝试创建 DevOps 管道以在 Linux Function App 中发布 Azure Function 项目。这是我迄今为止制作的管道:

pool:
  vmImage: ubuntu-latest

steps:
- task: UseDotNet@2
  inputs:
    version: '6.0.x'

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

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: |
      **/*.csproj      
    arguments: '--configuration Release'
    
- task: ArchiveFiles@2
  displayName: 'Archive Test'
  inputs:
    archiveType: 'zip'
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)/Test.Company.API/bin/Release/net6.0/'
    archiveFile: '$(System.DefaultWorkingDirectory)/Test.Company.API/bin/Release/net6.0/$(Build.BuildId).zip'

- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy - Test Company'
  inputs:
    azureSubscription: 'Test_Sub'
    appType: 'functionAppLinux'
    appName: 'test-company'
    package: '$(System.DefaultWorkingDirectory)/**/*.zip'
    runtimeStack: 'DOTNET|6.0'

这是我在上一个任务中看到的:

Got service connection details for Azure App Service:'test-company'
Trying to update App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"https://test.blob.core.windows.net/azure-pipelines-deploy/package_1659618746343.zip?***"}
Updated App Service Application settings.
Updated WEBSITE_RUN_FROM_PACKAGE Application setting to https://test.blob.core.windows.net/azure-pipelines-deploy/package_1659618746623.zip?***
Syncing triggers for function app
Sync triggers for function app completed successfully
Successfully added release annotation to the Application Insight : test_insights
App Service Application URL: https://test-company.azurewebsites.net
Finishing: Azure Function App Deploy - Test Company

但是,当我访问 Azure 目录中的 Azure 函数时,即使 DevOps 管道成功,函数也不会部署。

最佳答案

好的,我发现了问题。

我必须在ArchiveFiles@2下添加这一行

includeRootFolder: false

问题在于它正在创建一个包含根文件夹的 zip 文件,因此 host.json 位于 net6.0 内部,而不是根文件夹内。

我能够通过查看存储内的 zip 文件来了解问题。

我所做的另一项更改是发布应用程序而不是构建应用程序

以下是最终任务:

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    projects: '$(System.DefaultWorkingDirectory)/Test.API/Test.API.csproj'
    command: 'publish'
    arguments: '--configuration Release --output publish'
    publishWebProjects: false
    zipAfterPublish: false
    modifyOutputPath: false
    
- task: ArchiveFiles@2
  displayName: 'Archive Test'
  inputs:
    includeRootFolder: false
    replaceExistingArchive: true
    archiveType: 'zip'
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish'
    archiveFile: '$(System.DefaultWorkingDirectory)/Test.API/bin/Release/net6.0/$(Build.BuildId).zip'
    
- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy - Test'
  inputs:
    azureSubscription: 'Test_Sub'
    appType: 'functionAppLinux'
    appName: 'test'
    package: '$(System.DefaultWorkingDirectory)/**/*.zip'
    runtimeStack: 'DOTNET|6.0'

关于.net - 如何从 Devops 管道将 azure 函数发布到 Active Directory 中的 Azure Linux 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73237736/

相关文章:

.net - 一种从 .net 项目中检索所有字符串的方法?

.net - 支持 Compact Framework 的 IoC/DI Container

c# - 运算符==在基础中和在派生中等于

azure - 无法将私有(private) github 注册表中的 docker 镜像部署到 Azure 应用服务

Azure服务总线和公共(public)交通,相同的消息,不同的命名空间

c# - DocumentDB 分页标记。不断获得 "wrong"一个

azure-devops - VSTS : How to show related tests on a work item in backlog board?

azure-devops - Azure Pipelines - 处理相关下游管道的构建

image - 使用azure pipelines构建docker镜像仍然是401(未经授权)

c# - 如何实现策略模式的创建/工厂关注点?