Explore Courses Blog Tutorials Interview Questions
0 votes
in Azure by (7k points)
edited by

I have test automation code which reads some values from an environment variable stored on my local machine, like this:

Environment.GetEnvironmentVariable("SAUCE_USERNAME", EnvironmentVariableTarget.User);

Using Azure Pipelines to create this variable during pipeline execution and then read it in my test automation code. Using a YAML file.

I’m reading this variable in the VS Test step of the Azure Pipeline. If the variable is set, it needs to be for the life of Azure Pipeline.

I've tried to use the below, but have been unsuccessful.

Tried this code below as well but it fails with this error:

azure-pipelines.yml (Line: 39, Col: 1, Idx: 1252) - (Line: 39, Col: 1, Idx: 1252): While scanning a simple key, could not find expected ':'.
 # Create a secret variable

- powershell: |

Write-Host '##vso[task.setvariable variable=sauce.userName;issecret=true]abc'

# Attempt to output the value in various ways

- powershell: |

# Using an input-macro:

Write-Host "This works: $(sauce.userName)"

# Using the env var directly:

Write-Host "This does not work: $env:SAUCE_USERNAME"

# Using the mapped env var:

Write-Host "This works: $env:SAUCE_USERNAME"


SAUCE_USERNAME: $(sauce.userName)

1 Answer

0 votes
by (31.9k points)
edited by

Follow this:

Create variables in your pipeline and provide those variables with the values.

Create a Powershell script that you will run in the beginning to set your Environment Variables.

Run Posh in the beginning as a separate step in your CI pipeline and this will set the environment variables for the VM that's being used to run your pipeline.

Want to become Azure Developer, check out this Azure Tutorial.

Understand and implement Azure skills, by taking up Azure Online Training!

Browse Categories