0

I need to access Azure DevOps TFSGit repository from Azure cloudshell, is there a way to open a session with DevOps and issue commands to fetch the repository file contents. I am trying to implement Azure Policy initiatives as it has been depicted here. In the sample (link) the repos are on GitHub and it is public repository, i want to replicate this using Azure DevOps and with private repository.

Thanks.

user527614
  • 465
  • 5
  • 19
  • Hi, has the problem been resolved? I posted the answer you can use poweshell to get the content from your Azure DevOps Repo, does this help? If it helps resolve the issue, you can accept it as the answer. Or if you find any other solution, you can share it here and it could help those who met the same issue. Thanks! – Yang Shen - MSFT Mar 05 '20 at 07:00

1 Answers1

0

If you want to fetch the repository content. There's an existing api could help -- Items - Get.

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path={path}&api-version=5.1

You can check below poswer shell demo for more information about the usement.

PS C:\Users\****> $personalToken="*******************************"
PS C:\Users\****> $token=[System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalToken)"))
PS C:\Users\****> $header=@{authorization="Basic $token"}
PS C:\Users\****> $projectUrl ="https://dev.azure.com/********/********/_apis/git/repositories/51068825-de***********5671/items?path=Test.txt&api-version=5.1"
PS C:\Users\****> $content=Invoke-RestMethod -Uri $projectUrl -Method GET -contentType "application/json" -Headers $header
PS C:\Users\****> $content

enter image description here

enter image description here

Yang Shen - MSFT
  • 1,136
  • 1
  • 7
  • 9