VSTS-“允许脚本访问OAuth令牌"在哪里去了? [英] VSTS - Where has 'Allow Scripts to Access OAuth Token' gone?
问题描述
我有使用Powershell脚本访问VSTS API的VSTS构建,类似于
I have VSTS builds that use the Powershell script to access the VSTS API, similar to that detailed in Microsoft's Documentation.
文档指出:
要使您的脚本能够使用构建过程OAuth令牌,请转到构建定义的选项"标签,然后选择允许脚本访问OAuth令牌".
To enable your script to use the build process OAuth token, go to the Options tab of the build definition and select Allow Scripts to Access OAuth Token.
完成此操作后,您的脚本即可用于SYSTEM_ACCESSTOKEN 环境变量以访问VSTS REST API.例如:
After you've done that, your script can use to SYSTEM_ACCESSTOKEN environment variable to access the VSTS REST API. For example:
示例:
$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build-release/definitions/$($env:SYSTEM_DEFINITIONID)?api-version=2.0"
Write-Host "URL: $url"
$definition = Invoke-RestMethod -Uri $url -Headers @{
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
Write-Host "Definition = $($definition | ConvertTo-Json -Depth 1000)"
如Microsoft文档中所述,我确定您曾经去过Build> Options,然后单击允许脚本访问OAuth令牌",但是它不再存在(请参见下图).
As detailed in Microsofts Documentation, I'm sure you used to go to Build > Options and click 'Allow Scripts to Access OAuth Token', but it is no longer there (see pic below).
当我尝试构建时,会得到以下信息(对于我的旧构建而言不会发生):
When I try a build I get the following (which doesn't happen for my old builds):
Invoke-RestMethod: {"$ id":"1","innerException":null,"message":"TF400813:用户"是 无权访问此
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"TF400813: The user '' is not authorized to access this
此外,当我克隆一个构建(3个月前完成该构建时效果很好)时,该属性设置为false(原始属性设置为true).
In addition, when I clone a build (which worked nicely when I did it 3 months ago), the property is set to false (it's set to true on the original).
更新:如果我从VSTS导出,更改该属性然后再次导入,则可以正常工作,但是我确实需要没有这种手动干预的解决方案.
UPDATE: If I export from VSTS, change that property and import again, it works, but I really need a solution without this sort of manual intervention.
现在应该怎么做?
推荐答案
现在在代理阶段可用
这篇关于VSTS-“允许脚本访问OAuth令牌"在哪里去了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!