azureazure-devopsyamlazure-pipelines-yamlazure-deployment

Can an Azure YAML Pipelines deployment job type, have mutiple environment values?


Is there any possibility to have mutiple values in the environment property of deployment jobs? Something similar to this example:

stages:
    - stage: 
      jobs:
          - deployment: 
            environment:  
              - environmentOne
              - environmentTwo
            strategy:
              runOnce:
                deploy:
                  steps:
                    - script: echo hello

Micro doc do not make any allusion about that. I also found this blog, but for my case, the only porpuse of the environments is for the execution of the environment approvals and checks


Solution

  • The most simplified solution would be just to use the each keyword and object parameter to specify the environments.

    parameters:
    - name: environments
      type: object
      default: 
      - environmentOne
      - environmentTwo
    
    stages:
        - stage: 
          jobs:
          - ${{ each environment in parameters.environments }}:
            - deployment: 
              environment: ${{ environment }}
              strategy:
                runOnce:
                  deploy:
                    steps:
                      - script: echo hello