I am new to Playwright and Azure.
In my AZDO pipeline yaml file, I have a variable "environment_type" set to value "test" defined while we run the pipeline.
And it prints the value correctly as shown here:
- script: |
npm run test:$(environment_type)
displayName: "Run Playwright tests"
I have a further requirement where I want to run my Playwright tests in various other environments e.g. acc, dev, preprod etc
For that I already have all the necessary scripts inside package.json file.
I am writing the pipeline in a following way (not sure whats wrong in this code, because it is always printing the whole value as $(ENV_NAME_TEST5) in the password field
- script: |
npm run test:$(environment_type)
displayName: "Run Playwright tests"
env:
USERNAME: ‘user-name’
${{ if eq(variables['environment_type'], 'test') }}:
PASSWORD: '$(ENV_NAME_TEST)'
${{ elseif eq(variables['environment_type'], 'test2') }}:
PASSWORD: '$(ENV_NAME_TEST2)'
${{ elseif eq(variables['environment_type'], 'test3') }}:
PASSWORD: '$(ENV_NAME_TEST3)'
${{ elseif eq(variables['environment_type'], 'test4') }}:
PASSWORD: '$(ENV_NAME_TEST4)'
${{ else }}:
PASSWORD: '$(ENV_NAME_TEST5)'
After enabling the debug option in pipeline, I came to know that its not resolving these variables in the conditions.
I have tried to use various variables combinations syntaxes like compile time, run time. And also tried to place the variable block in various stages in the yaml file.
Could you please support me here? Thanks in advance!
You can use the Runtime parameters instead of the variables.
Here is my test sample yaml:
I set the
ENV_NAME_TESTvariables for the yaml pipeline in the UI.When we run the pipeline, we can change the
environment_typemanually before you run the pipeline and thePasswordwill be changed based on the parameter.Test result: