【问题标题】:TFS Build Solution failure: UnauthorizedAccess Microsoft.PowerShell.Commands.ImportModuleCommandTFS 构建解决方案失败:UnauthorizedAccess Microsoft.PowerShell.Commands.ImportModuleCommand
【发布时间】:2018-04-28 19:15:04
【问题描述】:

我正在尝试为 TFS 2017 On-Premise 设置我们的第一个构建代理。我使用了 2012 R2 服务器,安装了代理和 Visual Studio 2017。代理以正确的功能出现在 TFS 中。我采用了默认模板之一来构建 ASP.net 项目,并对其进行了尽可能少的更改。在第一次运行时,我可以看到获取源和更新 NuGet 包的前几个步骤成功完成。但是构建解决方案步骤失败了,我很难理解问题可能是什么。

构建日志显示如下:

2017-11-15T13:16:10.3583612Z ##[section]Starting: Build solution
2017-11-15T13:16:10.3583612Z ==============================================================================
2017-11-15T13:16:10.3583612Z Task         : Visual Studio Build
2017-11-15T13:16:10.3583612Z Description  : Build with MSBuild and set the Visual Studio version property
2017-11-15T13:16:10.3583612Z Version      : 1.119.0
2017-11-15T13:16:10.3583612Z Author       : Microsoft Corporation
2017-11-15T13:16:10.3583612Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613727)
2017-11-15T13:16:10.3583612Z ==============================================================================
2017-11-15T13:16:10.8588602Z Import-Module : AuthorizationManager check failed.
2017-11-15T13:16:10.8588602Z At line:1 char:453
2017-11-15T13:16:10.8588602Z + . ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPath ''variab ...
2017-11-15T13:16:10.8588602Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-11-15T13:16:10.8588602Z     + CategoryInfo          : SecurityError: (:) [Import-Module], PSSecurityException
2017-11-15T13:16:10.8588602Z     + FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
2017-11-15T13:16:10.9677474Z Invoke-VstsTaskScript : The term 'Invoke-VstsTaskScript' is not recognized as the name of a cmdlet, function, script 
2017-11-15T13:16:10.9677474Z file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct 
2017-11-15T13:16:10.9677474Z and try again.
2017-11-15T13:16:10.9677474Z At line:1 char:786
2017-11-15T13:16:10.9677474Z + ... tlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''\\ ...
2017-11-15T13:16:10.9677474Z +                    ~~~~~~~~~~~~~~~~~~~~~
2017-11-15T13:16:10.9677474Z     + CategoryInfo          : ObjectNotFound: (Invoke-VstsTaskScript:String) [], CommandNotFoundException
2017-11-15T13:16:10.9677474Z     + FullyQualifiedErrorId : CommandNotFoundException
2017-11-15T13:16:10.9677474Z  
2017-11-15T13:16:10.9989971Z ##[error]Exit code 1 returned from process: file name 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', arguments '-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPath ''variable:PSHOME'' } else { Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1'')) ; Import-Module -Name ([System.IO.Path]::Combine($PSHOME, ''Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1'')) }')) 2>&1 | ForEach-Object { Write-Verbose $_.Exception.Message -Verbose } ; Import-Module -Name '\\hidden-unc-path\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.119.0\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList @{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''\\hidden-unc-path\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.119.0\VSBuild.ps1'''))"'.
2017-11-15T13:16:10.9989971Z ##[section]Finishing: Build solution

【问题讨论】:

    标签: tfs azure-devops azure-pipelines


    【解决方案1】:

    您的 PowerShell 执行模式似乎设置为需要签名脚本才能执行。代理需要本地未签名的脚本才能运行:

    从管理员 PowerShell 控制台,运行:

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
         - scope LocalMachine
    

    然后重新启动代理。

    【讨论】:

    • 不幸的是,这并没有解决问题。我也试过无限制无济于事
    • 您可能需要使用 LocalMachine 范围,然后重新启动代理。
    • 还是没有区别
    猜你喜欢
    • 2016-03-02
    • 2019-01-02
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多