1

I am very new to Azure pipeline and I am stuck in an issue from pas one week. I have a Selenium c# test case which I have to execute on pipeline. I must use the Variable groups as the input parameters for my test cases. So, I have created appsettings.json file appsettings.json

In my YAML code, I am able to read the variable groups, but I am not able to use it's values in the pipeline.How to do it?

  • 1
    can you also provide a screenshot of the pipeline yaml you are using. You are also refer to these links for setting up selenium with a CICD pipeline : https://learn.microsoft.com/en-us/learn/modules/run-functional-tests-azure-pipelines/6-run-ui-tests?tabs=export-windows https://learn.microsoft.com/en-us/learn/modules/run-functional-tests-azure-pipelines/ – Rimaz Mohommed Mar 02 '21 at 23:20
  • @Sudhindra-sk Have you had a chance to check the provided solution? – Bhargavi Annadevara May 03 '21 at 05:09
  • It worked like a charm!!! :) – Sudhindra SK Jun 17 '21 at 02:59
  • @SudhindraSK Happy to help! Please consider [upvoting and accepting the answer](https://stackoverflow.com/help/someone-answers) if you found it helpful. :) – Bhargavi Annadevara Jun 24 '21 at 11:36
  • @SudhindraSK I'm trying to do something similar where I need to reference the variables from the variable group in other .json files in my repo. Works as expected in my build.yaml file but the reference doesn't work in the template.json. – paone Mar 01 '23 at 21:38

1 Answers1

1

To use a variable from a variable group, you need to add a reference to the group in your YAML file:

variables:
- group: my-variable-group

Thereafter variables from the variable group can be used in your YAML file.

If you use both variables and variable groups, you'll have to use name/value syntax for the individual (non-grouped) variables:

variables:
- group: my-variable-group
- name: my-bare-variable
  value: 'value of my-bare-variable'

To reference a variable group, you can use macro syntax or a runtime expression. In this example, the group my-variable-group has a variable named myhello.

variables:
- group: my-variable-group
- name: my-passed-variable
  value: $[variables.myhello] # uses runtime expression

steps:
- script: echo $(myhello) # uses macro syntax
- script: echo $(my-passed-variable)

You can also reference multiple variable groups in the same pipeline, and link an existing Azure key vault to a variable group and map selective vault secrets to the variable group.

Check Add & use variable groups for more information and examples. Refer to this blog post for a detailed walkthrough.

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30