<p>I read the environments documentation <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/process/environments?view=azure-devops" rel="nofollow noreferrer">here</a> and the issues opened under the environment resource, however I find it impossible to achieve my goal:</p>

<p>I would like to use a parametrized yaml template in order to deploy to multiple environments like below:</p>

<pre><code>parameters:
  pool_name: ''
  aks_namespace: ''
  environment: ''

jobs:
  - job: preDeploy
    displayName: preDeploy
    pool:
      name: $(pool_name)
    steps:
      - template: cd_step_prerequisites.yml


  - deployment: Deploy
    displayName: Deploy
    dependsOn: preDeploy
    condition: succeeded()
    variables:
      secret_name: acrecret
    pool:
      name: dockerAgents
    **environment: '$(environment).$(aks_namespace)'**
    strategy:
      runOnce:
        deploy:
          steps:
          - template: cd_step_aks_deploy.yml


  - job: postDeploy
    displayName: postDeploy
    dependsOn: Deploy
    condition: succeeded()
    pool:
      name: $(pool_name)
    steps:
      - template: cd_step_postrequisites.yml
</code></pre>

<p>I would like to use this approach so that I only host a minimal pipeline.yml next to my code, and then I would have all the templates in a different repo and call them from the main pipeline, as such:</p>

<pre><code>resources:
  repositories:
    - repository: self
    - repository: devops
      type: git
      name: devops

  - stage: CD1
    displayName: Deploy to Alpha
    jobs:
      **- template: pipeline/cd_job_api.yml@devops**
        parameters:
          pool_name: $(pool_name)
          aks_namespace: $(aks_namespace)
          app_name: $(app_name)
          app_image_full_name: $(app_image_full_name)
          environment: alpha
</code></pre>

<p>Then I would be able to pass the $environment variable in order to manipulate multiple deployment targets (AKS clusters/ groups of namespaces) from one template.
Currently this seems to be impossible as the default AzureDevOps parser fails when I try to run my pipeline, with the message "$(environment) environment does not contain x namespace" which tells me that the variable doesn't get expanded.</p>

<p>Is this planning to be implemented anytime soon? If not, are there any alternatives to use only one parametrized job template to deploy to multiple environments?</p>

Radu Zidarescu
<p>I think you would need to either parse the files and do a token replace with a script or there should be steps for that.</p>

<p>Your main alternative would be <a href="https://helm.sh/" rel="nofollow noreferrer">helm</a>. It allows to create templates and pass in variables to render those templates.</p>
