These are pipeline YAML snippets that I have found very handy.
Print all Environmental Variables
This is essential for debugging paths and composite variables.
- powershell: | gci 'env:' | sort name | ft -wrap displayName: 'List environment variables'
It generates an output similar to this. Notice that the environment variables are sorted and the trailing Format-Table with the -wrap parameter will ensure the values are not cut off at the end of the virtual line.
Name Value ---- ----- agent.jobstatus Succeeded AGENT_BUILDDIRECTORY C:\agent\_work\35 AGENT_DISABLELOGPLUGIN_TESTFIL true EPUBLISHERPLUGIN AGENT_DISABLELOGPLUGIN_TESTRES true ULTLOGPLUGIN AGENT_HOMEDIRECTORY C:\agent Path C:\agent\_work\_tool\NuGet\4.3.0\x64;C:\agent\externals\git\cmd;C:\wind ows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\Wi ndowsPowerShell;You_Get_The_Idea
If you only want to display the environment variables when System.Debug
is set to ‘true’ add the following condition to the code.
# Display all environment variables. - powershell: | gci 'env:' | sort name | ft -wrap condition: eq(variables['system.debug'], 'true') displayName: 'List environment variables'
Print all Folders under Source Folder
If I am debugging loading multiple repositories or just need to get confirmation that everything has loaded correctly. I display a tree view of the folders in my workspace.
- script: tree /a displayName: Tree view of project folders.
Notice that I have to use the /a
option so that plus signs (+), hyphens (-), and vertical bars(|) be used to draw the tree diagram. This way the we don’t get a bunch of invalid symbols when you look at the results.
C:. +---CheetahWheelies_BuildResources | +---MSBuild | | \---Falcon43 | \---Utilities | \---SDK-4.3 \---CheetahWheelies +---ProductX | +---ProductX | | +---Core | | | +---Interfaces | | | \---Rules | | +---CommonCode
Print all Files and Folders under Source Folder
For a deep dive, this snippet will print every file in the file system at and below the folder starting at a specified location. This is just an extension of the tree command shown above.
- script: tree "$(Build.ArtifactStagingDirectory)" /a /f displayName: Tree view of project artifact files and folders.