ossentoo
ossentoo

Reputation: 2019

Azure DevOps yaml pipeline - output variable from one job to another

I'm trying to pass a variable value from one job to another in a Azure Devops pipeline.

I've tried following the documentation in Microsoft docs diligently.
For example here:

However, it's not working as expected.

Can anyone point out where the problem is?

Here's the pipeline

https://github.com/ossentoo/azure-devops-pipelines

jobs:
- job: A
  steps:
  - script: echo "##vso[task.setvariable variable=applicationId;isOutput=true]629ae9cb-95e0-46b7-8a88-a4034b68323e"
    name: mytask

- job: B
  variables:
    newValue: $[dependencies.A.outputs['mytask.applicationId']]
  dependsOn: A
  steps:
  - powershell: |
      Write-Host "This value is: ${{variables.newValue}}"
    displayName: 'Output the value'

the output from this pipeline in the Powershell task is:

This value is: $[dependencies.A.outputs['mytask.applicationId']]

You can see the output here:

https://dev.azure.com/mercle/Concepts/_build/results?buildId=6151&view=logs&j=b79b690b-82d1-5750-8a0a-452d70195841&t=744de4c6-b805-5a86-cd25-7a780a8b3a55&l=12

It is almost as if $[] is not being recognized by Azure DevOps as a variable value.

thanks

Upvotes: 2

Views: 2526

Answers (1)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30313

In your last powershell step invoke newValue with $() syntax instead of ${{}}

- powershell: | Write-Host "This value is: $(newValue)"

I think the reason ${{}} not working might be that ${{}} is for parse time and executed before $[[]] is executed.

Upvotes: 4

Related Questions