Download files and folders from Azure DevOps
If you have a large repository it can be a long wait on the pipeline to get it checked out, only to use a few files. In this post, I will guide you through using PowerShell to download only the files you need with either the Azure DevOps REST API or CLI.
API Service
In both instances we will be using the REST API endpoint Get Items
This endpoint can return items from a Git repository within Azure DevOps, including its metadata, files content and/or the files themselves. There are multiple query parameters that affect the response of the API request. Below are the query parameters we will be using to download the JSON for either the files or folders metadata.
ScopePath
This is either the folder path or files path including the file name. The path should be relative to where it is within the repository not the file system.
For example:
File: /myexamplefolder/filename.txt
Folder: /myexamplefolder
VersionDescriptor.version
This is the name of the branch where to source the code from. If you use a dynamic method like the pre-defined variable System.SourceBranch
then you will need to remove the refs/heads/
to leave…