简体   繁体   English

如何使用 CI 管道部署 Azure Function?

[英]How to deploy a Azure Function using a CI pipeline?

Most of the time when I deploy a function, I do it through the publish profile.大多数时候,当我部署 function 时,我是通过发布配置文件来完成的。 However, I can't figure out how to deploy it through CI/CD.但是,我不知道如何通过 CI/CD 部署它。

When I try to do it through the deployment center on Azure, it doesn't work.当我尝试通过 Azure 上的部署中心进行操作时,它不起作用。 Where you go to deployment center -> Github -> Azure Pipelines -> select repository/branch -> deploy.你在哪里 go 到部署中心 -> Github -> Azure 存储库 -> Z999382812/bra->16EFE489 I think this is because my repository folder setup is not what it expects.我认为这是因为我的存储库文件夹设置不是它所期望的。 My setup is as follows我的设置如下

-Repo folder
--Project1
--Project1Function
---Function1.cs
---Project1Function.csproj
---host.json
--.gitignore
--Project1.sln

I think the issue is that Azure expects the Project1Function folder containing the host.json file to actually be in the root folder of the repository.我认为问题在于 Azure 期望包含 host.json 文件的 Project1Function 文件夹实际上位于存储库的根文件夹中。 The thing is that Project1Function references Project1 and basically just calls the code in Project1 as a function, which is why the repo is structured as such.问题是 Project1Function 引用了 Project1 并且基本上只是将 Project1 中的代码称为 function,这就是回购结构如此的原因。 So given this structure, how can I deploy it with CI through a pipeline?因此,鉴于这种结构,我如何通过管道使用 CI 部署它? I couldn't really find a good resource that describes how to do this, so a link to a tutorial/answer would be fine too.我真的找不到描述如何执行此操作的好资源,因此指向教程/答案的链接也可以。

Azure function can be deployed in a similar way Azure WebApp deploys. Azure function 可以以类似的方式部署 Azure WebApp 部署。 Follow a normal process of Build and deploy遵循正常的构建和部署流程

pool:
  name: Azure Pipelines
  demands:
  - msbuild
  - visualstudio

steps:
- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 4.4.1'
  inputs:
    versionSpec: 4.4.1

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '$(Parameters.solution)'
    vstsFeed: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '$(Parameters.solution)'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    clean: true

- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: publish
    publishWebProjects: false
    projects: |
     XXXXXX/XXXXXXXXXXX.csproj
     
    arguments: '-o $(Build.ArtifactStagingDirectory)/XXXXXXXXX -c Release'
    zipAfterPublish: false

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)/XXXXXXXXXX'
    ArtifactName: '$(Parameters.ArtifactName)'
  condition: succeededOrFailed()

steps:
- task: AzureRmWebAppDeployment@4
  displayName: 'Deploy Azure App Service'
  inputs:
    azureSubscription: 'Subscription Name'
    WebAppName: XXXXXX
    VirtualApplication: /
    packageForLinux: '$(System.DefaultWorkingDirectory)/_Pipelinename/drop/XXXXXX.zip'

I think this is the resource you're looking for Functions CI/CD我认为这是您正在寻找的资源Functions CI/CD

It would suggest the folder structure is the issue here.这表明文件夹结构是这里的问题。

Can you not have two separate projects in the same solution eg one for the Function App (with the required folder structure) and one for the other app and reference the Function App project in your other project?您能否在同一解决方案中没有两个单独的项目,例如一个用于 Function 应用程序(具有所需的文件夹结构),一个用于另一个应用程序并在您的另一个项目中引用 Function 应用程序项目?

That might help with getting the structure you need in your Function App project.这可能有助于在 Function App 项目中获得所需的结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM