title: YAML pipeline variable scopes
body: <p>I have a question regarding variables and their scopes. I want to set up a pipeline with multiple jobs and each job contains the same tasks and I want to use a template for them.
  I also have job variables in them which I want to manipulate during the job runtime. Since the Job is defined in a template all variable names are the same. Usually I use the following command to set the new value for a variable.</p>
  <pre><code>Write-Output (&quot;##vso[task.setvariable variable=job_variable1;]$newValue&quot;)
  </code></pre>
  <p>I don't really know if this causes all variables from all jobs being set with the content of $newVariable or if this logging command just sets the variable from the current job.</p>
  <p>All jobs run in parallel and if this would also set the variable from other jobs it could cause side effects in other jobs.</p>
  <p>I tested this problem with the following yaml pipeline and as far as I can see it looks good and the new value which is set in BuildJob1 isn't echoed in BuildJob2 but I don't really know if it's a valid test.</p>
  <pre><code>trigger: none
  
  jobs:
  - job: BuildJob1
    variables:
      job_variable1: VariableFromJob1    # this is only available in BuildJob
    steps:
    - task: PowerShell@2
      displayName: &quot;Echo and set job variable&quot;
      inputs:
        targetType: inline
        script: '
        echo &quot;initial job variable&quot;;
        echo &quot;$(job_variable1)&quot;;
        $newValue = &quot;new Variable for VariableFromJob1&quot;;
        Write-Output (&quot;##vso[task.setvariable variable=job_variable1;]$newValue&quot;);
        '
    - task: PowerShell@2
      displayName: &quot;Echo new job variable&quot;
      inputs:
        targetType: inline
        script: '
        echo &quot;new job variable&quot;;
        echo &quot;$(job_variable1)&quot;;
        '
  - job: BuildJob2
    variables:
      job_variable1: VariableFromJob2    # this is only available in BuildJob
    steps:
    - task: PowerShell@2
      displayName: &quot;Echo and set job variable&quot;
      inputs:
        targetType: inline
        script: '
        echo &quot;initial job variable&quot;;
        Start-Sleep -s 45;
        echo &quot;$(job_variable1)&quot;;
        $newValue = &quot;newJobValue from job 2&quot;;
        Write-Output (&quot;##vso[task.setvariable variable=job_variable1;]$newValue&quot;);
        '
    - task: PowerShell@2
      displayName: &quot;Echo new job variable&quot;
      inputs:
        targetType: inline
        script: '
        echo &quot;new job variable&quot;;
        echo &quot;$(job_variable1)&quot;;
        '
  
  </code></pre>
  <p>In Job2 I waited 45 seconds to be sure that the job variable is set in Job1 before printing its content.</p>