VSTS - Where has 'Allow Scripts to Access OAut

2019-02-25 06:22发布

I have VSTS builds that use the Powershell script to access the VSTS API, similar to that detailed in Microsoft's Documentation.

The document states:

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.

After you've done that, your script can use to SYSTEM_ACCESSTOKEN environment variable to access the VSTS REST API. For example:

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)"

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).

enter image description here

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: The user '' is not authorized to access this

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).

enter image description here

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.

How should this be done now please?

1条回答
来,给爷笑一个
2楼-- · 2019-02-25 07:17

It is available in the agent phase now

enter image description here

查看更多
登录 后发表回答