Search code examples
azure-devopsazure-functionsazure-pipelines

How to configure Azure pipeline approval check to deploy to Azure function apps?


We have 2 pipelines to deploy to our Azure function apps. One for dev and one for prod. The one for dev triggers automatically and doesn't require any approval. But the one for Prod triggers manually and requires approval check. Both pipelines are using a same service connection. Not sure how can I configure the approval check because when I go to the Environment I can only add 'Kubernetes' and 'Virtual Machines' as a resource.

trigger: 
  branches:
    include:
      - master
  paths:
    include:
      - function-app/**

resources:
  repositories:
    - repository: aomdevops
      type: git
      name: AOM-Core/AOM-Devops

variables:
  - name: postmanEnv
    value: "postman/telco_local.postman_environment.json"

pool:
  vmImage: ubuntu-latest

stages:
  - stage: Deploy
    jobs:
      - job: DeployExtractInfo
        displayName: "Deploy Extract Info"
        steps:
          - template: templates/funcapp-deployment.yaml
            parameters:
              faName: 'funcapp-xxxxxxxxx'
              resourceGroup: 'xxxxxxxxxxxxxxxx'
              azureSvcConn: 'aom-azure'
              funcAppFolder: 'function-app/xxxxxxxxxxx/'
              funcAppName: 'exInfo'

      - job: DeployErrorHandling
        displayName: "Deploy Error Handling"
        steps:
          - template: templates/funcapp-deployment.yaml
            parameters:
              faName: 'xxxxxxxxxxxxxxxxxxxxxx'
              resourceGroup: 'xxxxxxxxxxxxxxxxx'
              azureSvcConn: 'aom-azure'
              funcAppFolder: 'function-app/xxxxxxxxxx/'
              funcAppName: 'errHandling'

Solution

  • The Environments i used as the target of deployments on the deployment type job. See "jobs.deployment definition" and "jobs.deployment.environment definition".

    jobs:
    - deployment: deploy
      environment: environmentName.resourceName
      . . .
    

    Currently, the supported resource types (resourceType) in Environments are only virtualMachine and Kubernetes. Azure Function App is not supported.

    For your case, you can use the ManualValidation@0 task to set up manual approvals in your YAML pipeline like as below.

    # azure-pipelines.yml
    
    stages:
    - stage: Deploy
      jobs:
      - job: approval
        displayName: 'Wait for Approval'
        pool: server
        timeoutInMinutes: 4320
        steps:
        - task: ManualValidation@0
          timeoutInMinutes: 1440
          inputs:
            notifyUsers: |
              [email protected]
              [email protected]
            instructions: 'Please validate and approve this deployment.'
            onTimeout: 'reject'
      
      - job: DeployExtractInfo
        displayName: 'Deploy Extract Info'
        dependsOn: approval
        . . .
    
      - job: DeployErrorHandling
        displayName: 'Deploy Error Handling'
        dependsOn: approval
        . . .
    

    With this method, when to run the Deploy stage, it will first to run the approval job to wait for the specified users to approve. Once approved, it will start to run the subsequent DeployExtractInfo and DeployErrorHandling jobs.