Search code examples
azure-devopsazure-pipelinesazure-powershellazure-pipelines-release-pipelineazure-cli

How to read release pipeline variable and use as environment variable in Azure DevOps in Azure CLI task?


I am using one powershell task and one Azure Cli task in release pipeline of Azure DevOps. I have some release pipeline's variables. I want to read those variables as they will be required by my script in above two tasks. I used powershell core in Azure cli task

enter image description here

I tried to read them in the inline script directly as $(variableName) or $env:variableName but none of the above worked.

I tried to set read the variable in Environment variables option in the task and then use in the inline scripts using $env:variableName but it also didn't work. On printing the variableName in the script using Write-Host, the value I got is $(valueName) instead of the correct value. enter image description here

How to read those variables inside these scripts?


Solution

  • The pipeline variables can be reference in the Azure CLI inline script by using the syntax $(variableName). I tested by adding the following in a script

    write-host "The variable value: $(variableName)"