SLN
SLN

Reputation: 5082

How to set a variable from another yaml file in azure-pipeline.yml

I have an environment.yml shown as follow, I would like to read out the content of the name variable (core-force) and set it as a value of the global variable in my azure-pipeline.yamal file how can I do it?

name: core-force
channels:
  - conda-forge
dependencies:
  - click
  - Sphinx
  - sphinx_rtd_theme
  - numpy
  - pylint
  - azure-cosmos
  - python=3
  - flask
  - pytest
  - shapely

in my azure-pipeline.yml file I would like to have something like

variables:
  tag: get the value of the name from the environment.yml aka 'core-force'

Upvotes: 2

Views: 9377

Answers (2)

DreadedFrost
DreadedFrost

Reputation: 2970

Global variables should be stored in a separate template file. This file ideally would be in a separate repo where other repos can refer to this.

Here is another answer for this

Upvotes: 0

Krzysztof Madej
Krzysztof Madej

Reputation: 40533

Please check this example:

File: vars.yml

variables:
  favoriteVeggie: 'brussels sprouts'

File: azure-pipelines.yml

variables:
- template: vars.yml  # Template reference

steps:
- script: echo My favorite vegetable is ${{ variables.favoriteVeggie }}.

Please note, that variables are simple string and if you want to use list you may need do some workaraund in powershell in place where you want to use value from that list.

If you don't want to use template functionality as it is shown above you need to do these:

  • create a separate job/stage
    • define step there to read environment.yml file and set variables using REST API or Azure CLI
  • create another job/stage and move you current build defitnion into there

I found this topic on developer community where you can read:

Yaml variables have always been string: string mappings. The doc appears to be currently correct, though we may have had a bug when last you visited.

We are preparing to release a feature in the near future to allow you to pass more complex structures. Stay tuned!

But I don't have more info bout this.

Upvotes: 7

Related Questions