0

We are planning to move our release pipelines to yaml and we are ready with it.

I have multiple environments like dev, test and prod where I'm trying to use same deployment job templates for all environments.

jobs:
- deployment: deploy
  displayName: Deploy
  environment: 
    name: dev     # This should be replaced with environment specific variable
    resourceType: VirtualMachine
    tags: WEB01

In above code, my intension is to provide name as environment specific variable. Could someone pls help?

Thank you!

Kart
  • 53
  • 2
  • 8

2 Answers2

2

You can do this with parameters, but you need to use the expression syntax which is evaluated when the pipeline is compiled

parameters:
  - name: environment
    type: string
    default: dev
    values:
      - dev
      - test
      - preprod
      - prod

jobs:
  - deployment: deploy
    displayName: Deploy
    environment: 
      name: ${{ parameters.environment }}
      resourceType: VirtualMachine
      tags: WEB01
James Reed
  • 13,873
  • 51
  • 60
  • We have added multiple deployment jobs in templates and when im using parameters, it is throwing error like "A value for environment parameter must be provided." – Kart Mar 02 '22 at 07:43
  • @Kart Could you provide an example of your pipeline and template? – James Reed Mar 09 '22 at 10:54
0

You might like my answer in another post. it does stages per environment with approvals.

https://stackoverflow.com/a/74159554/4485260

T Brown
  • 1,385
  • 13
  • 9