您可以通过 PowerShell 调用 REST API。
设定值(Put请求):
https://[vsts name].extmgmt.visualstudio.com/_apis/ExtensionManagement/InstalledExtensions/{publisherName}/{extension id}/Data/Scopes/User/Me/Collections/%24settings/Documents?api-version=3.1-preview.1
正文(内容类型:application/json)
{
"id": "myKey",
"__etag": -1,
"value": "myValue"
}
获取值(获取请求):
https://[vsts name].extmgmt.visualstudio.com/_apis/ExtensionManagement/InstalledExtensions/{publisherName}/{extension id}/Data/Scopes/User/Me/Collections/%24settings/Documents/mykey?api-version=3.1-preview.1
发布者名称和扩展 ID 可以在包 json 文件中获取(例如 vss-extension.json)
关于通过PowerShell调用REST API,可以参考这篇文章:Calling VSTS APIs with PowerShell
调用 REST API 的简单示例:
Param(
[string]$vstsAccount = "<VSTS-ACCOUNT-NAME>",
[string]$projectName = "<PROJECT-NAME>",
[string]$buildNumber = "<BUILD-NUMBER>",
[string]$keepForever = "true",
[string]$user = "",
[string]$token = "<PERSONAL-ACCESS-TOKEN>"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$uri = "https://$($vstsAccount).visualstudio.com/DefaultCollection/$($projectName)/_apis/build/builds?api-version=2.0&buildNumber=$($buildNumber)"
$result = Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
用于获取基本 URL 的 PowerShell 脚本:
Function GetURL{
param([string]$url)
$regex=New-Object System.Text.RegularExpressions.Regex("https:\/\/(.*).visualstudio.com")
$match=$regex.Match($url)
if($match.Success)
{
$vstsAccount=$match.Groups[1]
$resultURL="https://$vstsAccount.extmgmt.visualstudio.com"
}
}
GetURL "https://codetiger.visualstudio.com/"