简体   繁体   English

执行 Azure DevOps API 调用构建租赁需要什么权限

[英]What permissions are required to perform Azure DevOps API calls for leases of builds

So I am trying to figure out a way I can remove leases on specific builds via the AzureDevOps API.因此,我试图找出一种方法,可以通过 AzureDevOps API 删除特定构建的租约。 I have a PAT with read/execute permissions on Builds and read/write permissions on test management.我有一个 PAT,对构建具有读/执行权限,对测试管理有读/写权限。 I've also tried various other permissions without anything working.我还尝试了各种其他权限,但没有任何效果。 Below is the script I am trying to use.下面是我尝试使用的脚本。

$token = "{PAT}"
$url="https://{instance}/{collection}/{project}/_apis/build/retention/leases/{lease Id}?api-version=6.0-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

When I try to get or delete builds this works fine (with a different URL of course).当我尝试获取或删除构建时,这可以正常工作(当然,使用不同的 URL)。 But when I try to get a lease I always get a 401 error.但是当我尝试获得租约时,我总是会收到 401 错误。 I've looked all over the API documentation but I can't find anywhere it says specifically what permissions the PAT needs to gain access.我已经查看了 API 文档,但我找不到任何地方明确说明 PAT 需要哪些权限才能获得访问权限。 What specific permissions are required for the leases?租约需要哪些特定权限? Or do I just need to go about formatting my header in a different way?还是我只需要 go 以不同的方式格式化我的 header ?

Thanks for any help, please let me know if I can provide any additional information.感谢您的帮助,如果我可以提供任何其他信息,请告诉我。

Check this doc Leases - Delete :检查此文档租赁 - 删除

DELETE https://dev.azure.com/{organization}/{project}/_apis/build/retention/leases?ids={ids}&api-version=6.1-preview.1

PAT scope is: vso.build_execute PAT scope 是: vso.build_execute

By the way, I try to switch the doc version to Azure DevOps Server 2019, but I get the message: The requested page is not available for Azure DevOps Server 2019顺便说一句,我尝试将文档版本切换到 Azure DevOps Server 2019,但我收到消息: The requested page is not available for Azure DevOps Server 2019

You could try to catch the API via F12 and then check it in the NetWork tab.您可以尝试通过 F12 捕获 API,然后在“网络”选项卡中检查它。

Update1更新1

Thanks for Andrew sharing.感谢安德鲁分享。

We could vote or follow this ticket to get the latest news.我们可以投票或关注这张以获取最新消息。

Update2更新2

If we create PAT token with full access, we could get and delete leases, check the pic below如果我们创建具有完全访问权限的 PAT 令牌,我们可以获取和删除租约,请查看下图

GET得到

在此处输入图像描述

DELETE删除

在此处输入图像描述

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM