我尝试从powershell脚本调用我的私有代理的分析API,我收到以下错误响应:
[error]Invoke-RestMethod : {"error":{"code":"0","message":"Using this service requires \"View Analytics\" permission on
我检查了“查看分析”的安全设置,并显示“允许”。
PAT我已设置我的私人代理,并且已启用所有范围。
我可以通过Postman使用另一个PAT授权Basic来访问此API。
另外,如果我在PowerShell脚本中更改我的标题:
$header = @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
为:
$header = @{Authorization = "Basic <hard coded base64 encoded string used in the header for my Postman queries>"}
它有效。
问题:发生了什么事?
答案 0 :(得分:1)
System_Accesstoken
是在构建/发布期间动态生成的令牌,它不是您用于配置代理的令牌。
您用于配置代理的令牌仅用于代理的初始配置。
授予构建/发布服务帐户的权限:
project collection build service
搜索框,然后选择Project Collection build Service (xxx)
用户(不是群组)View analytics
设为允许。答案 1 :(得分:0)
您需要授予允许脚本访问OAuth令牌。为此,请转到管道,选择一个阶段,然后在“在代理上运行”上启用“允许脚本访问OAuth令牌”。
How to Allow scripts to access the OAuth token
除此之外,您还必须为用户“期望的请求”(在这种情况下为“查看分析”)授予用户“项目集合构建服务(xxx)”的访问权限,但可以是编辑任务组,编辑管道等。