title: How to set and read user environment variable in Azure DevOps Pipeline?
body: <p>I have some test automation code that reads some values from an environment variable stored on my local machine, like this:</p>
  
  <pre><code>Environment.GetEnvironmentVariable("SAUCE_USERNAME", EnvironmentVariableTarget.User);
  </code></pre>
  
  <p>I'm trying to use Azure Pipelines to create this variable during pipeline execution and then read it in my test automation code. Using a YAML file.</p>
  
  <p>Im reading this variable in the VS Test step of the Azure Pipeline. So if I set the variable, it has to be for the life of the Azure Pipeline.</p>
  
  <p>I've tried to use the documentation <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=vsts&amp;tabs=yaml%2Cbatch" rel="noreferrer">here</a> but have been unsuccessful.</p>
  
  <p>Tried this code below as well but it fails with this error:</p>
  
  <blockquote>
    <p>azure-pipelines.yml (Line: 39, Col: 1, Idx: 1252) - (Line: 39, Col: 1,
    Idx: 1252): While scanning a simple key, could not find expected ':'.</p>
  </blockquote>
  
  <pre><code># 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"
  env:
  SAUCE_USERNAME: $(sauce.userName)
  </code></pre>