Answers: <p>For deployment jobs check this format <code>$[dependencies.&lt;job-name&gt;.outputs['&lt;job-name&gt;.&lt;step-name&gt;.&lt;variable-name&gt;']]</code>. Documentation: <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops#support-for-output-variables" rel="nofollow noreferrer">Support for output variables</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2024-01-31T16:32:47.737Z
Answers: 2024-01-31T16:32:47.737Z
Answers: Shamrai Aleksander
Answers: <p>While executing deployment strategies, you can access output variables across jobs using the following syntax.</p>
  <p>For runOnce strategy: $[dependencies..outputs['..']] (for example, $[dependencies.JobA.outputs['JobA.StepA.VariableA']])
  For runOnce strategy plus a resourceType: $[dependencies..outputs['<em>..']]. (for example, $[dependencies.JobA.outputs['Deploy_VM1.StepA.VariableA']])
  For canary strategy: $[dependencies..outputs['</em>..']]
  For rolling strategy: $[dependencies..outputs['_..']]</p>
  <p><a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops#support-for-output-variables" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops#support-for-output-variables</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2024-03-07T16:20:07.253Z
Answers: 2024-03-07T16:20:07.253Z
Answers: geeky_girl
Body: <p>I have a pipeline with multiple jobs. I would like to send the output that I am setting in a powershell script to another job in the pipeline.</p>
  <p>I have followed several examples to do this, like: 'https://medium.com/microsoftazure/how-to-pass-variables-in-azure-pipelines-yaml-tasks-5c81c5d31763' and 'https://devops.stackexchange.com/questions/17604/how-do-i-refer-in-azure-pipelines-to-an-output-variable-defined-in-a-previous-st'.</p>
  <p>I can access the output variables that I am setting if the tasks are in the same job, but in different jobs the variables are empty.</p>
  <p>This is my current pipeline:</p>
  <pre><code>- stage: DeploytoDev
    displayName: Deploy to Dev
    condition: ${{ eq(variables['Build.SourceBranch'], 'refs/heads/develop') }}
    jobs:     
      - deployment: DeployInfraDev
        environment: env
        strategy:
          runOnce:
            deploy:
              steps:
              - task: AzureResourceManagerTemplateDeployment@3
                displayName: 'Infra Deployment: Storage Account, Function App Develop'
              
                inputs:
                  deploymentScope: 'Subscription'
                  azureResourceManagerConnection: '$(serviceConnectionDev)'
                  action: 'Create Or Update Resource Group'
                  subscriptionName: '$(subscriptionDev)'
                  resourceGroupName: '$(resourceGroup)'
                  location: '$(location)'
                  templateLocation: 'Linked artifact'
                  csmFile: '$(Pipeline.Workspace)/$(infraArtifactName)/templates/main.bicep'
                  overrideParameters: &gt;-
                    -appName $(appName) 
                    -stage dev 
                    -location $(location)
                  deploymentMode: 'Incremental'
                  deploymentName: 'DeployPipelineTemplate'
                  deploymentOutputs: 'deploymentOutputs'
                name: 'deployment'
            
              - task: PowerShell@2
                name: 'outputVariables'
                displayName: 'Set Deployment Output Variables'
                inputs:
                  targetType: inline
                  script: |
                    $armOutputObj = '$(deploymentOutputs)' | ConvertFrom-Json
                  
                    $armOutputObj.PSObject.Properties | ForEach-Object {
                      $keyname = $_.Name
                      $value = $_.Value.value
  
                      # Creates a standard pipeline variable
                      Write-Output &quot;##vso[task.setvariable variable=$keyName;isOutput=true]$value&quot;
  
                      # Display keys in pipeline
                      Write-Output &quot;output variable: $keyName $value&quot;
                    }
                    Write-Output &quot;##vso[task.setvariable variable=test;isOutput=true]test&quot;
  
                  pwsh: true
  
              - bash: echo &quot;$(outputVariables.test) | $(outputVariables.storageAccountName)&quot;
  
      - job: BuildWebsite
        dependsOn: DeployInfraDev
        variables:
          storageAccountName: $[ dependencies.DeployInfraDev.outputs['outputVariables.storageAccountName'] ]
          storageAccountNameFoo: $[ dependencies.DeployInfraDev.outputs['outputVariables.test'] ]
        steps:
          - bash: echo &quot;$(storageAccountName) | $(storageAccountNameFoo)&quot;
          - bash: echo &quot;$storageAccountName | $storageAccountNameFoo&quot;
            env: 
              storageAccountName: $(storageAccountName)
              storageAccountNameFoo: $(storageAccountNameFoo)
  </code></pre>
  <p>Image of the Bash inline scripts of the jobs:</p>
  <ul>
  <li><p>Same job bash script:</p>
  <p><a href="https://i.sstatic.net/M6ext.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/M6ext.png" alt="enter image description here" /></a></p>
  </li>
  <li><p>Different Job without setting env variables in task</p>
  <p><a href="https://i.sstatic.net/tSXVo.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/tSXVo.png" alt="enter image description here" /></a></p>
  </li>
  <li><p>Different Job while setting env variables in task</p>
  <p><a href="https://i.sstatic.net/zuZly.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zuZly.png" alt="enter image description here" /></a></p>
  </li>
  </ul>
  <p>I was expecting that in both bash scripts in the 'BuildWebsite' Job would print the same values as the bash script from the 'DeployInfraDev' Job.</p>
  
Tags: <azure-devops><azure><azure-pipelines><pipeline>
Title: Why are the outputs variables that I am passing from one job to another showing empty in Azure pipelines?
UserDisplayName: krakergig
ThreadText: # Why are the outputs variables that I am passing from one job to another showing empty in Azure pipelines?
  
  (Asked by: username_0 on 2024-01-19)
  
  I have a pipeline with multiple jobs. I would like to send the output that I am setting in a powershell script to another job in the pipeline.
  
  I have followed several examples to do this, like: 'https://medium.com/microsoftazure/how-to-pass-variables-in-azure-pipelines-yaml-tasks-5c81c5d31763' and 'https://devops.stackexchange.com/questions/17604/how-do-i-refer-in-azure-pipelines-to-an-output-variable-defined-in-a-previous-st'.
  
  I can access the output variables that I am setting if the tasks are in the same job, but in different jobs the variables are empty.
  
  This is my current pipeline:
  
  ```
  - stage: DeploytoDev
    displayName: Deploy to Dev
    condition: ${{ eq(variables['Build.SourceBranch'], 'refs/heads/develop') }}
    jobs:     
      - deployment: DeployInfraDev
        environment: env
        strategy:
          runOnce:
            deploy:
              steps:
              - task: AzureResourceManagerTemplateDeployment@3
                displayName: 'Infra Deployment: Storage Account, Function App Develop'
              
                inputs:
                  deploymentScope: 'Subscription'
                  azureResourceManagerConnection: '$(serviceConnectionDev)'
                  action: 'Create Or Update Resource Group'
                  subscriptionName: '$(subscriptionDev)'
                  resourceGroupName: '$(resourceGroup)'
                  location: '$(location)'
                  templateLocation: 'Linked artifact'
                  csmFile: '$(Pipeline.Workspace)/$(infraArtifactName)/templates/main.bicep'
                  overrideParameters: >-
                    -appName $(appName) 
                    -stage dev 
                    -location $(location)
                  deploymentMode: 'Incremental'
                  deploymentName: 'DeployPipelineTemplate'
                  deploymentOutputs: 'deploymentOutputs'
                name: 'deployment'
            
              - task: PowerShell@2
                name: 'outputVariables'
                displayName: 'Set Deployment Output Variables'
                inputs:
                  targetType: inline
                  script: |
                    $armOutputObj = '$(deploymentOutputs)' | ConvertFrom-Json
                  
                    $armOutputObj.PSObject.Properties | ForEach-Object {
                      $keyname = $_.Name
                      $value = $_.Value.value
  
                      # Creates a standard pipeline variable
                      Write-Output "##vso[task.setvariable variable=$keyName;isOutput=true]$value"
  
                      # Display keys in pipeline
                      Write-Output "output variable: $keyName $value"
                    }
                    Write-Output "##vso[task.setvariable variable=test;isOutput=true]test"
  
                  pwsh: true
  
              - bash: echo "$(outputVariables.test) | $(outputVariables.storageAccountName)"
  
      - job: BuildWebsite
        dependsOn: DeployInfraDev
        variables:
          storageAccountName: $[ dependencies.DeployInfraDev.outputs['outputVariables.storageAccountName'] ]
          storageAccountNameFoo: $[ dependencies.DeployInfraDev.outputs['outputVariables.test'] ]
        steps:
          - bash: echo "$(storageAccountName) | $(storageAccountNameFoo)"
          - bash: echo "$storageAccountName | $storageAccountNameFoo"
            env: 
              storageAccountName: $(storageAccountName)
              storageAccountNameFoo: $(storageAccountNameFoo)
  
  ```
  
  Image of the Bash inline scripts of the jobs:
  
  * Same job bash script:
  
    [![enter image description here](https://i.sstatic.net/M6ext.png)](https://i.sstatic.net/M6ext.png)
  * Different Job without setting env variables in task
  
    [![enter image description here](https://i.sstatic.net/tSXVo.png)](https://i.sstatic.net/tSXVo.png)
  * Different Job while setting env variables in task
  
    [![enter image description here](https://i.sstatic.net/zuZly.png)](https://i.sstatic.net/zuZly.png)
  
  I was expecting that in both bash scripts in the 'BuildWebsite' Job would print the same values as the bash script from the 'DeployInfraDev' Job.
  
  **Tags:** azure-devops, azure, azure-pipelines, pipeline
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2024-01-31. Score: 0
  
  For deployment jobs check this format `$[dependencies.<job-name>.outputs['<job-name>.<step-name>.<variable-name>']]`. Documentation: [Support for output variables](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops#support-for-output-variables)
  
  
  ---
  
  ### Answer by username_2 on 2024-03-07. Score: 0
  
  While executing deployment strategies, you can access output variables across jobs using the following syntax.
  
  For runOnce strategy: $[dependencies..outputs['..']] (for example, $[dependencies.JobA.outputs['JobA.StepA.VariableA']])
  For runOnce strategy plus a resourceType: $[dependencies..outputs['*..']]. (for example, $[dependencies.JobA.outputs['Deploy\_VM1.StepA.VariableA']])
  For canary strategy: $[dependencies..outputs['*..']]
  For rolling strategy: $[dependencies..outputs['\_..']]
  
  <https://learn.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops#support-for-output-variables>
  
  
  ---
  
  