【问题标题】:Azure DevOps build pipeline with hosted agent failing托管代理失败的 Azure DevOps 构建管道
【发布时间】:2020-01-01 08:14:41
【问题描述】:

我对 Azure 和 TFS 以及相关方面还是很陌生。所以,如果我在这里混淆了条款,请原谅。

我正在使用本地安装测试 Microsoft Team Foundation Server 的功能。我不是服务器本身的管理员,我拥有对其中一个项目的管理员访问权限。

我在这个项目中有一个带有一些 python 代码的 git repo,我正在尝试为此设置 CI 构建管道。我也在手动配置一个代理来运行这个构建管道。目前,我正在配置我正在处理的 Windows 机器以作为代理运行。我能够将其设置为侦听作业,并且当从 TFS 服务器提交时它也会获取作业。 (我正在从 cmd.exe 窗口运行代理) 但是,作为构建管道的一部分,即使是最简单的命令行任务,我也无法让它完成。

下面是where python的输出:

2019-08-27T14:41:15.1614046Z ##[section]Starting: Find python version
2019-08-27T14:41:15.1623937Z ==============================================================================
2019-08-27T14:41:15.1624042Z Task         : Command Line
2019-08-27T14:41:15.1624091Z Description  : Run a command line script using cmd.exe on Windows and bash on macOS and Linux.
2019-08-27T14:41:15.1624157Z Version      : 2.146.1
2019-08-27T14:41:15.1624203Z Author       : Microsoft Corporation
2019-08-27T14:41:15.1624258Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
2019-08-27T14:41:15.1625058Z ==============================================================================
2019-08-27T14:41:15.6151701Z Cannot invoke method. Method invocation is supported only on core types in this language mode.
2019-08-27T14:41:15.6151921Z At line:1 char:1
2019-08-27T14:41:15.6151968Z + . ([scriptblock]::Create('if (!$PSHOME) { $null = Get-Item -LiteralPa ...
2019-08-27T14:41:15.6152019Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-08-27T14:41:15.6152077Z     + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
2019-08-27T14:41:15.6152123Z     + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage
2019-08-27T14:41:15.6152156Z  
2019-08-27T14:41:17.7569608Z Cannot invoke method. Method invocation is supported only on core types in this language mode.
2019-08-27T14:41:17.7569833Z At line:1 char:740
2019-08-27T14:41:17.7570630Z + ... Continue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create ...
2019-08-27T14:41:17.7571090Z +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-08-27T14:41:17.7572452Z     + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
2019-08-27T14:41:17.7574051Z     + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage
2019-08-27T14:41:17.7574178Z  
2019-08-27T14:41:17.8271008Z ##[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 'C:\TOOLS\agent\_work\_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.146.1\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1' -ArgumentList @{ NonInteractive = $true } -ErrorAction Stop ; $VerbosePreference = 'SilentlyContinue' ; $DebugPreference = 'SilentlyContinue' ; Invoke-VstsTaskScript -ScriptBlock ([scriptblock]::Create('. ''C:\TOOLS\agent\_work\_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.146.1\cmdline.ps1'''))"'.
2019-08-27T14:41:17.8301183Z ##[section]Finishing: Find python version

当我在我的机器中以交互方式从命令行执行该命令时,该命令运行良好。

为什么在管道运行时调用 PowerShell?为什么要执行这么长的命令来执行如此简单的事情?

提前感谢您提供的任何建议。

【问题讨论】:

    标签: azure powershell tfs azure-devops azure-pipelines


    【解决方案1】:

    代理在幕后使用 PowerShell,看起来您的 IT 在阻止运行某些 PowerShell 脚本(可能仅从远程运行)的计算机中设置了一些安全性。

    尝试在你的 PowerShell 中运行它:

    $ExecutionContext.SessionState.LanguageMode
    

    我猜你会得到这个输出:

    ConstrainedLanguage
    

    如果是,尝试切换到FullLanguage

    $ExecutionContext.SessionState.LanguageMode = "FullLanguage"
    

    如果它没有帮助,可能它也被阻止了,所以你需要与 IT 交谈,将更改它或尝试更改注册表,如 here 解释或将环境变量 __PSLockdownPolicy 设置为 0

    【讨论】:

    • 感谢您的回答!。我认为受约束的语言肯定是问题所在。我必须看看 IT 是否同意为我更改设置。这些命令不能在“ConstrainedLanguage”模式下运行吗?我正在尝试对代理做一些简单的事情。没有可能需要管理员权限。
    猜你喜欢
    • 2020-06-08
    • 2021-01-03
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-27
    • 2021-01-21
    • 1970-01-01
    相关资源
    最近更新 更多