简体   繁体   English

Azure DevOps 使用 REST API 调用 GetItem

[英]Azure DevOps calling GetItem using REST API

I'm trying to get the file contents of a file (sonar-project.properties) in Azure Devops but I can't seem to get the actual content.我正在尝试在 Azure Devops 中获取文件(sonar-project.properties)的文件内容,但我似乎无法获得实际内容。 Here is my powershell code when trying to call the REST api.这是我在尝试调用 REST api 时的 powershell 代码。 I want to get the content of the sonar-project.properties file that sits in the root directory of the repo.我想获取位于 repo 根目录中的 sonar-project.properties 文件的内容。

$uri = "https://dev.azure.com/$organization/$projectId/_apis/git/repositories/$repoId/Items?
                        path=sonar-project.properties&
                        recursionLevel=0&
                        versionDescriptor.version=$branchName&
                        versionDescriptor.versionOptions=0&
                        versionDescriptor.versionType=Branch&
                        includeContent=true&
                        resolveLfs=true&
                        api-version=6.1-preview.1"

$item = (Invoke-WebRequest -Uri $uri -Proxy http:\\webproxy.sweetcompany.ca:1080 -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ProxyUseDefaultCredentials -Method Get).Content | ConvertFrom-Json

And here is my output:这是我的 output:

Repo: newmicroservice-repo
Branch: refs/heads/master
objectId      : 9804b758e84cac41a6acc4d011f57310a1f63102
gitObjectType : tree
commitId      : e911bc994bb3dad69580baa0b44e6dc029e3adad
path          : /
isFolder      : True
url           : https://dev.azure.com/BLAHBLAH/GUIDSGUIDS/_apis/git/repositories/GUIDSGUIDS/items?path=%2F&versionType=Branch&versionOptions=None...

Now I know the isFolder is set to true, but the sonar-project.properties is an actual file.现在我知道 isFolder 设置为 true,但 sonar-project.properties 是一个实际文件。 So I am at a loss right now.. Any ideas?所以我现在不知所措..有什么想法吗?

You could try the following PowerShell Rest API Sample: I also use this rest api: Items - Get to get the file content from Git Repo type. You could try the following PowerShell Rest API Sample: I also use this rest api: Items - Get to get the file content from Git Repo type.

$token = "PAT"

$url=" https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/git/repositories/{RepoId}/items?recursionLevel=0&versionDescriptor.version=master&versionDescriptor.versionOptions=0&versionDescriptor.versionType=Branch&includeContent=true&resolveLfs=true&path=sonar-project.properties&6.1-preview.1"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get  -ContentType application/json

Write-Host "$response"

Repo structure:回购结构:

在此处输入图像描述

Result:结果:

在此处输入图像描述

暂无
暂无

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

相关问题 在PowerShell中使用Azure DevOps REST API更新内部版本定义 - Update build definition using Azure DevOps REST API in PowerShell 使用 Rest API 在 Azure Devops 中创建工作项时出错 - Error while creating Work Item in Azure Devops using Rest API 使用 REST API Azure devops 传递变量组名称 - Pass a Variable group name using REST API Azure devops 如何使用 Azure DevOps REST API 设置发布定义工件 - How to set Release Definition artifacts using Azure DevOps REST API 使用 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 如何使用 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 CloudShell 访问 Azure DevOps REST API? - How to access Azure DevOps REST API from Azure CloudShell using PowerShell? 如何使用 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 DevOps Rest API对Azure Pipelines Powershell任务进行身份验证 - Authenticate Azure Pipelines Powershell task against Azure DevOps Rest API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM