0

I'm using the below azure-pipeline.yml file to build docker image, push to Azure docker registry & restart the Azure docker app servicer.

This yaml file uses variable set in azure pipeline, screenshot attached.

My issue is, I need to create 2-3 pipelines every-week for different projects I need to add every variable manually for each project and copy paste from my config. Is there a way I can import a .env file or add multiple variables all at once while creating the pipeline.

Objectively I need to cut down the single variable copy paste time & avoid errors that might occurr

enter image description here

1
  • Any reason you're not putting them in the YAML file's variables block? Commented Dec 26, 2022 at 12:21

1 Answer 1

2

1.You could use variable group to reuse variables.

trigger: 
- none

pool:
  vmImage: ubuntu-latest

variables:
- group: forTest

steps:
- script: |
    echo $(test1)
    echo $(test2)
  displayName: 'Run a multi-line script'

enter image description here

2.You could use variable template.

trigger: 
- none

pool:
  vmImage: ubuntu-latest

variables:
- template: vars.yml

steps:

- script: |
    echo $(test1)
    echo $(test2)
  displayName: 'Run a multi-line script'

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Another good thing about this, is that if the variables are the same or name are the same, you can clone the variable group and just change the values accordingly
Thanks for the answer Jiawei, I use the same .azure-piplines.yml file to deploy multiple environments like staging/prod etc in multiple pipelines. Each environment has it's own variables defined in pipelines is there anyways I can use different values for different pipelines? Using the same yaml file
If you want to use the same azure-piplines.yml, you just need to modify the content of vars.yml for different projects. You could add multiple variables all at once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.