我正在尝试运行一个访问 VSTS API 的 powershell 脚本,如果我在 PowerShell ISE 中运行它,它就可以正常工作。但是我需要在 VSTS 的发布过程中将脚本添加为任务,并且出现安全错误。我得到的错误是:
AuthorizationManager 检查失败。CategoryInfo : SecurityError: (:) [], PSSecurityExceptionfullyQualifiedErrorId : UnauthorizedAccess
该脚本只是从特定构建中获取工作项,然后将这些工作项保存到如下文件中
function Invoke-ServiceGetBuilds($headers)
{
Invoke-RestMethod -Uri https://myaccount.visualstudio.com/DefaultCollection/My-Software/_apis/build/builds?api-version=2.0"&"minFinishTime=2016-12-01"&"buildNumber=master_*"&"resultFilter=succeeded -headers $headers -Method Get
return $result
}
$username = "usr"
$password = "pass*"
$filePath = "file.html"
$releaseName = ""
$basicAuth = ("{0}:{1}" -f $username, $password)
$basicAuth = [System.Text.Encoding]::UTF8.GetBytes($basicAuth);
$basicAuth = [System.Convert]::ToBase64String($basicAuth)
$headers = @{Authorization=("Basic {0}" -f $basicAuth)}
$returnedBuilds = Invoke-ServiceGetBuilds $headers
#...create the object and the array of workitems HTML
ConvertTo-Html -body "<h2>Build Information and WI</h2> $workItemsHtml" -Title "Release Report" | Out-File $filePath
如果我从 PowerShell ISE 运行该脚本但在 VSTS 中失败,该脚本运行良好关于如何解决此问题的任何想法