title: Resolving Predefined Agent Variables in Runtime Expressions
body: <p>I have the following scenario, it is simplified for the sake of brevity, but outlines my problem.</p>
  <p>I have a 2 Job pipeline.</p>
  <p><code>BreakMatrix</code> Job: A job that runs on an <code>AdminPool</code> and outputs 2 variables with the following names <code>ENV1</code> and <code>ENV2</code>. The names are <strong>important</strong> because each of them matches the name of an Environment running in a separate <code>MachinePool</code> VM deployment pool.</p>
  <p><code>Upgrade</code> Job: A deployment job that depends on the <code>BreakMatrix</code> job and that runs on a VM <em>MachinePool</em>, with a tag that will select <code>ENV1</code> and <code>ENV2</code> environments.</p>
  <p>I am trying to pass in one of the variables to each of the corresponding Environments:</p>
  <pre class="lang-yaml prettyprint-override"><code>    - job: BreakMatrix
        pool: AdminPool
        steps:
        - checkout: none
        - powershell: |
            $result1 = @{&quot;Hostname&quot; = &quot;Env1Value&quot;}
            $result2 = @{&quot;Hostname&quot; = &quot;Env2Value&quot;}
            Write-Host &quot;##vso[task.setvariable variable=ENV1;isOutput=true;]$result1&quot;
            Write-Host &quot;##vso[task.setvariable variable=ENV2;isOutput=true;]$result2&quot;
          name: outputter
  
      - deployment: Upgrade
        dependsOn: BreakMatrix
        variables:
          agentName: $(Environment.ResourceName)
          agentName2: $(Agent.Name)
          formatted: $[ format('outputter.{0}', variables['agentName']) ]
          result1: $[ dependencies.BreakMatrix.outputs[format('outputter.{0}', variables['agentName'])] ]
          result2: $[ dependencies.BreakMatrix.outputs[format('outputter.{0}', variables['agentName2'])] ]
          result3: $[ dependencies.BreakMatrix.outputs[format('outputter.{0}', variables['Agent.Name'])] ]
          hardcode: $[ dependencies.BreakMatrix.outputs['outputter.ENV2'] ]
          json: $[ convertToJson(dependencies.BreakMatrix.outputs) ]
        environment:
          name: MachinePool
          resourceType: VirtualMachine
          tags: deploy-dynamic
        strategy:
          rolling:
            preDeploy:
              steps:
                - powershell: |
                    echo 'Predeploy'
                    echo &quot;agentName: $(agentName)&quot;
                    echo &quot;agentName2: $(agentName2)&quot;
                    echo &quot;env: $(Environment.ResourceName)&quot;
                    echo &quot;formatted: $(formatted)&quot;
                    echo &quot;harcode: $(harcode)&quot;
                    echo &quot;result1: $(result1)&quot;
                    echo &quot;result2: $(result2)&quot;
                    echo &quot;result3: $(result3)&quot;
                    echo &quot;json: $(json)&quot;
            deploy:
              steps:
                - powershell: |
                    echo 'Deploy'
  </code></pre>
  <p>Output for <code>ENV2</code> pre-deploy step:</p>
  <pre><code>Predeploy
  agentName: ENV2
  agentName2: ENV2
  env: ENV2
  formatted: outputter.ENV2
  hardcode: {
  Hostname:Env2Value}
  result1: 
  result2: 
  result3: 
  json: {
    
  outputter.ENV2: 
  \&quot;Hostname\&quot;:\&quot;Env2Value\&quot;
  
  }
  
  </code></pre>
  <p>If i try to use a <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&amp;tabs=yaml#agent-variables-devops-services" rel="nofollow noreferrer">predefined variable</a> in a <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&amp;tabs=yaml%2Cbatch#use-outputs-in-a-different-job" rel="nofollow noreferrer">dependency expression</a> they don't seem to properly resolve, but if i just simply map them to a variable / format them they work.
  Note: The environment names are actually dynamically calculated before these jobs run so I cannot use parameters or static/compile time variables.</p>
  <p>Any suggestions on how to pass in only the relevant variable to each of the environments ?</p>