Answers: <p>Create a variable group for each environment, containing the environment-specific parameter values.</p>
  <p>In your parameterized templates, reference the variables from the respective variable group. These templates can be reused across different deployments.</p>
  <p>In your individual pipeline YAML files, include the parameterized templates and link them to the appropriate variable group based on the deployment environment.</p>
  <p>When you trigger a pipeline for a specific environment, Azure DevOps will automatically inject the values from the corresponding variable group into the templates. This allows you to achieve dynamic configuration without having to manually modify YAML files each time.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-08-31T16:27:09.920Z
Answers: 2023-08-31T16:27:09.920Z
Answers: geeky_girl
Body: <p>We have large application we deploy from ADO using classic pipelines. In the process of converting over to yaml. The application is made up of multiple smaller apps which are deployed individually into multiple environments. The environments are being added and removed as projects commence and complete so it is not a fixed list.</p>
  <p>The problem is we will need to update 20-30 yamls each time the list changes.</p>
  <p>We are using templates to reuse code extensively. The question is - can we have a master list of environments and parameters that can be read into each deployment at deploy time?</p>
  <p>Here is a example snippet of the pipeline code we use - calls out to our deployment yaml for each environment/stage:</p>
  <pre><code>extends:
    template: pipelines/main.yml@templates
      deployStages:
        - template: stages/deploy.yml@templates
          parameters:
            dependsOn: buildContainer
            deploySteps:
              - template: ./app-deploy.yml
                parameters:
                  serviceConnection: test
            environment: test
            poolName: 'Azure Pipelines'
            runIfNotMainOrMaster: ${{ eq(parameters.action, 'Deploy') }}
            variableGroup: 'test'
        - template: stages/deploy.yml@templates
          parameters:
            dependsOn: deploy_test
            deploySteps:
              - template: ./app-deploy.yml
                parameters:
                  serviceConnection: staging
            environment: stage
            poolName: 'Azure Pipelines'
            variableGroup: 'staging'
        - template: stages/deploy.yml@templates
          parameters:
            dependsOn: deploy_stage
            deploySteps:
              - template: ./app-deploy.yml
                parameters:
                  serviceConnection: production
            environment: prd1
            poolName: 'Azure Pipelines'
            variableGroup: 'prd1'
  </code></pre>
  <p>etc.</p>
  
Tags: <azure><azure-pipelines><yaml>
Title: Re-using deployment stages in multiple YAMLs
UserDisplayName: Ceefla
ThreadText: # Re-using deployment stages in multiple YAMLs
  
  (Asked by: username_0 on 2023-05-03)
  
  We have large application we deploy from ADO using classic pipelines. In the process of converting over to yaml. The application is made up of multiple smaller apps which are deployed individually into multiple environments. The environments are being added and removed as projects commence and complete so it is not a fixed list.
  
  The problem is we will need to update 20-30 yamls each time the list changes.
  
  We are using templates to reuse code extensively. The question is - can we have a master list of environments and parameters that can be read into each deployment at deploy time?
  
  Here is a example snippet of the pipeline code we use - calls out to our deployment yaml for each environment/stage:
  
  ```
  extends:
    template: pipelines/main.yml@templates
      deployStages:
        - template: stages/deploy.yml@templates
          parameters:
            dependsOn: buildContainer
            deploySteps:
              - template: ./app-deploy.yml
                parameters:
                  serviceConnection: test
            environment: test
            poolName: 'Azure Pipelines'
            runIfNotMainOrMaster: ${{ eq(parameters.action, 'Deploy') }}
            variableGroup: 'test'
        - template: stages/deploy.yml@templates
          parameters:
            dependsOn: deploy_test
            deploySteps:
              - template: ./app-deploy.yml
                parameters:
                  serviceConnection: staging
            environment: stage
            poolName: 'Azure Pipelines'
            variableGroup: 'staging'
        - template: stages/deploy.yml@templates
          parameters:
            dependsOn: deploy_stage
            deploySteps:
              - template: ./app-deploy.yml
                parameters:
                  serviceConnection: production
            environment: prd1
            poolName: 'Azure Pipelines'
            variableGroup: 'prd1'
  
  ```
  
  etc.
  
  **Tags:** azure, azure-pipelines, yaml
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-08-31. Score: 0
  
  Create a variable group for each environment, containing the environment-specific parameter values.
  
  In your parameterized templates, reference the variables from the respective variable group. These templates can be reused across different deployments.
  
  In your individual pipeline YAML files, include the parameterized templates and link them to the appropriate variable group based on the deployment environment.
  
  When you trigger a pipeline for a specific environment, Azure DevOps will automatically inject the values from the corresponding variable group into the templates. This allows you to achieve dynamic configuration without having to manually modify YAML files each time.
  
  
  ---
  
  