1
votes

I'm defining an Azure Pipeline as code in which there will be several deployment stages (staging and production). I need the production stage to be executed on approval from some users.

Currently there's a way to define approvals for "Environments". However this only includes resources such as VMs and K8s, but the application will be deployed on Azure App Services:

enter image description here

enter image description here

Pipeline scerpt:

  - stage: Deploy_Production
    pool:
      vmImage: ubuntu-latest
    jobs:
      - job: deploy
        steps:
        - script: find ./
        - task: DownloadBuildArtifacts@0
          inputs:
            buildType: 'current'
            downloadType: 'single'
            artifactName: 'drop'
            downloadPath: '$(System.ArtifactsDirectory)'
        - script: 'find $(System.ArtifactsDirectory)'
        - task: AzureRmWebAppDeployment@4
          inputs:
            ConnectionType: 'AzureRM'
            azureSubscription: 'Free Trial(xxx)'
            appType: 'webAppLinux'
            WebAppName: 'app'
            packageForLinux: '$(System.ArtifactsDirectory)/**/*.jar'
            RuntimeStack: 'JAVA|11-java11'
            StartupCommand: 'java - jar $(System.ArtifactsDirectory)/drop/build/libs/app.jar'

How can I configure approvals in this scenarios?

UPDATE:

Following MorrowSolutions' answer I updated my pipeline

  1. If I leave it as shown in the answer, the steps entry is highlighted as invalid syntax:

enter image description here

  1. If I indent it, it seems to be correct. The deployment stage executes and downloads the artifact, but nothing else seems to be executed (scripts, deploy task...):

enter image description here

enter image description here

1

1 Answers

0
votes

So, the resources you tie to an environment do not restrict which pipelines can be associated with that environment. Also, they're not required and at the moment Microsoft only supports Kubernetes & VMS, so you won't be able to associate an Azure App Service.

In your case, don't associate any resources with your environment. You'll want to update your YAML to use a deployment job specifically and specify the environment within your parameters. This will tell your pipeline to associate releases with the environment you've configured. It should look something like this in your case:

stages:
- stage: Deploy_Production
  pool:
    vmImage: ubuntu-latest
  jobs:
    - deployment: DeployWeb
      displayName: Deploy Web App
      environment: YourApp-QA
      pool:
        vmImage: 'ubuntu-latest'
      strategy:
        runOnce:
          deploy:
            steps:
                - script: find ./
                - task: DownloadBuildArtifacts@0
                  inputs:
                    buildType: 'current'
                    downloadType: 'single'
                    artifactName: 'drop'
                    downloadPath: '$(System.ArtifactsDirectory)'
                - script: 'find $(System.ArtifactsDirectory)'
                - task: AzureRmWebAppDeployment@4
                  inputs:
                    ConnectionType: 'AzureRM'
                    azureSubscription: 'Free Trial(xxx)'
                    appType: 'webAppLinux'
                    WebAppName: 'app'
                    packageForLinux: '$(System.ArtifactsDirectory)/**/*.jar'
                    RuntimeStack: 'JAVA|11-java11'
                    StartupCommand: 'java - jar $(System.ArtifactsDirectory)/drop/build/libs/app.jar'

Here is Microsoft's documentation on the deployment job schema, with more information on how to use the environment parameter:

I actually just had a conversation with someone about this. You're not alone in thinking that the resources you tie to an environment have to be associated with the resources you're deploying within your YAML pipeline :)