Dump all VSTS variables in Windows or Linux based agents with one line of codeAug 6, 2018 | Utkarsh Shigihalli | 1 min read DevOps Build
Ever wanted to dump all the VSTS variables during CI or CD pipeline in VSTS? Also want it to work in both Linux and Windows MS hosted agents? I know on windows machines, you can do write few lines in PowerShell to get the exact same thing. But this involves few lines of code and also does not work in Linux machines. In this blog post I will show you simple way to quickly dump all the VSTS variables with just one line of code. Yes! just one line of code.
The solution is to use the
Bash step in your pipeline.
The benefit of this command is that, this also works in both Windows and Linux based hosted agents.
Okay, the first thing you need is a bash task. You add this to your build/release pipeline is by searching for Bash task.
Next step is to configure the task. Select
Inline and in the script box, write the magic line.
1 printenv | sort
Notice I also pipe it and pass it to
sort to sort the variables.
Once your build starts, it will look like below in the VSTS hosted windows agent
And on the hosted Ubuntu agent, it will look exactly the same.
Isn’t it great?
BTW, if for some reason you dislike bash task and only targeting Windows agents, there is alternate way of dumping all variables using
Command Line task. Just add the task and in the script text box enter below command
1 cmd /k set
Thanks for reading!