[英]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.