在运行PowerShell脚本的Visual Studio Online中,AuthorizationManager检查失败

时间:2016-12-08 15:51:22

标签: powershell azure-pipelines-release-pipeline

我正在尝试运行访问VSTS API的powershell脚本,如果我在PowerShell ISE中运行它,它可以正常工作。 但我需要在VSTS的发布过程中将脚本添加为任务,我收到安全错误。我得到的错误是:

  

AuthorizationManager检查失败。   CategoryInfo:SecurityError:(:) [],PSSecurityException   FullyQualifiedErrorId: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中失败,该脚本运行良好 关于如何解决这个问题的任何想法

0 个答案:

没有答案