Use
Write-Output "##vso[task.setvariable variable=testvar;isOutput=true;]testvalue"
Then reference the output variable as if it exists from a future task.
$(taskreference.testvariable)
The task reference name can be set on the output section of the powershell script task:
But it looks like cross-job references aren't available yet, when I read the docs:
TODO
I am not sure how are we going to generate Job ref name, since we don’t have job chaining at this point.
It should be something like:
{DefinitionName}_{JobName}
So for now the variable will only work within the same Job.
It does look like YAML build do already support cross-phase output variable references.
jobs:
# Set an output variable from job A
- job: A
pool:
vmImage: 'vs2017-win2016'
steps:
- powershell: echo "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the value"
name: setvarStep
- script: echo $(setvarStep.myOutputVar)
name: echovar
# Map the variable into job B
- job: B
dependsOn: A
pool:
vmImage: 'ubuntu-16.04'
variables:
myVarFromJobA: $[ dependencies.A.outputs['setvarStep.myOutputVar'] ] # map in the variable
# remember, expressions require single quotes
steps:
- script: echo $(myVarFromJobA)
name: echovar