如何将两个压缩函数部署到同一个 Azure Function App?

How to deploy two zipped Functions to the same Azure Function App?

我试图将两个压缩函数部署到同一个名为 http-trigger-api-test 的 Azure Function App,结果是第一个被部署但随后被第二个函数替​​换。

我在以下 yaml 文件中有任务:

- stage: Build
  displayName: Build stage for Azure Function
  jobs:
  - job: Build
    steps:

    - task: ArchiveFiles@2
      displayName: 'Archive HttpTriggerApi Azure Function'
      inputs:
        rootFolderOrFile: 'azure/azure_functions/HttpTriggerApi/function_code'
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true

    - task: ArchiveFiles@2
      displayName: 'Archive HttpTriggerApiWeb Azure Function'
      inputs:
        rootFolderOrFile: 'azure/azure_functions/HttpTriggerApi/function_code_web'
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId)2.zip
        replaceExistingArchive: true

    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      displayName: 'Upload Azure Function Full Stack'
      artifact: full_stack_deploy

    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId)2.zip
      displayName: 'Upload Azure Function Web Stack'
      artifact: web_deploy

- stage: TEST
  displayName: Deploy stage Test
  variables:
  - group: optimizelyeventconnector-test-group    
  jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: optimizelyeventconnector-test
    pool:
      vmImage: $(vmImageName)
    strategy:
      runOnce:
       deploy:
        steps:

       - task: AzureCLI@1
        displayName: 'Deploy Azure Function Full Stack'
        inputs:
          azureSubscription: 'test-group-SPN'
          scriptType: 'ps'
          scriptLocation: 'inlineScript'
          inlineScript: |
            az functionapp deployment source config-zip -g test-group -n http-trigger-api-test --src $(Pipeline.Workspace)/full_stack_deploy/$(Build.BuildId).zip

      - task: AzureCLI@1
        displayName: 'Deploy Azure Function Web Stack'
        inputs:
          azureSubscription: 'test-group-SPN'
          scriptType: 'ps'
          scriptLocation: 'inlineScript'
          inlineScript: |
            az functionapp deployment source config-zip -g test-group -n http-trigger-api-test --src $(Pipeline.Workspace)/web_deploy/$(Build.BuildId)2.zip

我读过一些问题,建议不要将多个功能打包到一个功能应用程序中,除非它们是相关的。就我而言,这两个功能都是相关的。

欢迎对这个问题提出任何建议、评论或改进。

经过一番研究,我找到了解决方案。

我必须按以下方式构建我的函数应用程序:

- main_function_app
  - functions
    - Full_Stack
        - configAPI.json
        - configAPITest.json
        - function.json
        - index.js
    - Web  
        - configAPI.json
        - configAPITest.json
        - function.json
        - index.js
    - host.json
    - local.settings.json
    - package-lock.json
    - package.json
    - proxies.json
    - utils.js

部署到azure时,需要安装node、依赖、压缩文件并发布。

- stage: Build
  displayName: Build stage for Azure Function
  jobs:
    - job: Build
        displayName: Build
        pool:
           vmImage: $(vmImageName)
steps:
- task: NodeTool@0
  inputs:
    versionSpec: '14.x'
  displayName: 'Install Node.js'

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: 'npm install --prefix azure/azure_functions/HttpTriggerApi/main_function_app/functions'

- task: ArchiveFiles@2
  displayName: 'Build Azure Functions and Dependencies'
  inputs:
    rootFolderOrFile: 'azure/azure_functions/HttpTriggerApi/main_function_app/functions'
    includeRootFolder: false
    archiveType: zip
    archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
    replaceExistingArchive: true

- upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
  displayName: 'Publish Azure Functions Artifact'
  artifact: functions