简体   繁体   中英

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. However, I can't figure out how to deploy it through CI/CD.

When I try to do it through the deployment center on Azure, it doesn't work. Where you go to deployment center -> Github -> Azure Pipelines -> select repository/branch -> deploy. 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. 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. So given this structure, how can I deploy it with CI through a pipeline? 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. 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

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?

That might help with getting the structure you need in your Function App project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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