Search code examples
azure-devopsazure-pipelinesazure-pipelines-release-pipelineazure-pipelines-build-task

Set VSTS output variable to be result from bash command


I'm running a task in VSTS which performs some operations on a variable from a previous step and I then need to output the result to be used in future tasks. I have the following in a command line task running on a linux build host but am having no luck when trying to use the result later with $(podName3).

COMMAND="$(echo '$(pods)' | grep -oh -P '[^ ]*' | grep schema)"
##vso[task.setvariable variable=podName3]"$COMMAND"

I have tried several variations on this to no avail and need some direction as this has stumped me for too long now


Solution

  • Seems the syntax is incorrect.

    Just try to below format:

    COMMAND="$(echo '$pods' | grep -oh -P '[^ ]*' | grep schema)"
    echo "##vso[task.setvariable variable=podName3]$COMMAND"
    

    Or add a powershell task and run below commands to set the variable:

    $COMMAND="$(echo '$env:pods' | grep -oh -P '[^ ]*' | grep schema)"
    
    Write-Host "##vso[task.setvariable variable=podName3]$COMMAND"
    

    More information please see Define and modify your variables in a script