简体   繁体   English

如何使用 PowerShell 从 Azure CloudShell 访问 Azure DevOps REST API?

[英]How to access Azure DevOps REST API from Azure CloudShell using PowerShell?

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.我需要从 Azure cloudshell 访问 Azure DevOps TFSGit 存储库,有没有办法打开与 DevOps 的会话并发出命令来获取存储库文件内容。 I am trying to implement Azure Policy initiatives as it has been depicted here .我正在尝试实施 Azure Policy 计划,如此处所述 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.在示例(链接)中,存储库位于 GitHub 上,它是公共存储库,我想使用 Azure DevOps 和私有存储库复制它。

Thanks.谢谢。

If you want to fetch the repository content.如果要获取存储库内容。 There's an existing api could help -- Items - Get .有一个现有的 api 可以提供帮助 - 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.您可以查看下面的 poswer shell 演示以获取有关使用的更多信息。

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

在此处输入图片说明

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Devops REST API 搜索带有 Powershell 的 Azure Devops 代码存储库并输出到 CSV - How to search Azure Devops Code Repos w/ Powershell using Devops REST API and output to CSV 在PowerShell中使用Azure DevOps REST API更新内部版本定义 - Update build definition using Azure DevOps REST API in PowerShell 使用 Powershell 的 Azure Devops 审计 rest api 延续令牌 - Azure Devops audit rest api continuation token using powershell Azure devops rest api 结果使用 powershell 脚本循环 - Azure devops rest api result looping using powershell script 如何使用 powershell(Azure devops REST API)获取用户提交更改的 Azure devops git repo 文件夹名称 - How to get Azure devops git repo folder name where user committed changes using powershell (Azure devops REST API) Azure REST API 访问与 Z2F2D399F0EA8844859FE5514B304B73 - Azure REST API access with powershell Need Rest API使用PowerShell从Azure Devops获取权限详细信息 - Need Rest API to get the permission details from Azure Devops using PowerShell 使用 REST API in Z531B84AD41B2A753DA83ACF3 从 Azure DevOps Repo 获取文件 - Get file from Azure DevOps Repo Using REST API in Powershell Script 如何通过Azure DevOps REST API使用PowerShell创建功能以及链接的任务? - How do you create a feature along with linked tasks using PowerShell via the Azure DevOps REST API? 如何使用 powershell 使用 Azure DevOps 获取发布状态(成功、失败) - How to get status of the release (success, failure) with powershell using Azure DevOps Rest API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM