How to pass a value in a text file to Azure Devops variable and use in another task

Viewed 1753

I have the following Powershel script that reads a text file. The value that is read is a value I want to pass as a variable to another step in the Azure Devops yml file

$data = Get-Content .\cluster_txt.txt
Write-Output $data

How can I access the value in $data in another task

1 Answers

You suppose to use logging command to create Azure Pipelines variable

Write-Host "##vso[task.setvariable variable=testvar;]$data"

and then in next task you can reffer to variable as

$(testvar)

or

$env:TESTVAR

Be aware that Azure Pipelines variable will not be available in the task you will create it. And if you need variable in another job or stage then you need output variable. Here you will find how to use it.

Related