我正在遵循这个tutorial to automate the creation of release notes using the wiki in Azure DevOps。步骤非常基本,并且没有太多变量会导致错误。
当我创建一个版本时,它会运行,然后在PowerShell任务中失败。这是日志中显示的内容,并带有错误:
[错误]无法将术语“powershell.exe”识别为cmdlet、函数、脚本文件或可操作程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
我已将日志中的座席名称替换为 [myLocalAgent]
2020-03-10T08:46:58.0567080Z ##[debug]Evaluating condition for step: 'PowerShell Script'
2020-03-10T08:46:58.0567721Z ##[debug]Evaluating: succeeded()
2020-03-10T08:46:58.0567840Z ##[debug]Evaluating succeeded:
2020-03-10T08:46:58.0568071Z ##[debug]=> True
2020-03-10T08:46:58.0568346Z ##[debug]Result: True
2020-03-10T08:46:58.0568583Z ##[section]Starting: PowerShell Script
2020-03-10T08:46:58.0660872Z ==============================================================================
2020-03-10T08:46:58.0660963Z Task : PowerShell
2020-03-10T08:46:58.0661006Z Description : Run a PowerShell script on Linux, macOS, or Windows
2020-03-10T08:46:58.0661050Z Version : 2.165.0
2020-03-10T08:46:58.0661103Z Author : Microsoft Corporation
2020-03-10T08:46:58.0661147Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2020-03-10T08:46:58.0661190Z ==============================================================================
2020-03-10T08:46:59.2751397Z ##[debug]VstsTaskSdk 0.11.0 commit 7ff27a3e0bdd6f7b06690ae5f5b63cb84d0f23f4
2020-03-10T08:46:59.4510283Z ##[debug]Entering C:\[myLocalAgent]\_work\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.165.0\powershell.ps1.
2020-03-10T08:46:59.4641263Z ##[debug]Loading resource strings from: C:\[myLocalAgent]\_work\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.165.0\task.json
2020-03-10T08:46:59.5013258Z ##[debug]Loaded 11 strings.
2020-03-10T08:46:59.5070774Z ##[debug]SYSTEM_CULTURE: 'en-US'
2020-03-10T08:46:59.5667676Z ##[debug]Loading resource strings from: C:\[myLocalAgent]\_work\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.165.0\Strings\resources.resjson\en-US\resources.resjson
2020-03-10T08:46:59.6018496Z ##[debug]Loaded 11 strings.
2020-03-10T08:46:59.6361663Z ##[debug]INPUT_ERRORACTIONPREFERENCE: 'stop'
2020-03-10T08:46:59.6401971Z ##[debug]INPUT_FAILONSTDERR: 'false'
2020-03-10T08:46:59.6440102Z ##[debug] Converted to bool: False
2020-03-10T08:46:59.6470870Z ##[debug]INPUT_IGNORELASTEXITCODE: 'false'
2020-03-10T08:46:59.6491840Z ##[debug] Converted to bool: False
2020-03-10T08:46:59.6521051Z ##[debug]INPUT_PWSH: 'false'
2020-03-10T08:46:59.6543374Z ##[debug] Converted to bool: False
2020-03-10T08:46:59.6572719Z ##[debug]INPUT_WORKINGDIRECTORY: 'C:\[myLocalAgent]\_work\r7\a'
2020-03-10T08:46:59.6748678Z ##[debug]Asserting container path exists: 'C:\[myLocalAgent]\_work\r7\a'
2020-03-10T08:46:59.6782331Z ##[debug]INPUT_TARGETTYPE: 'inline'
2020-03-10T08:46:59.6826977Z ##[debug]INPUT_SCRIPT: '# Get content of releasenotes
2020-03-10T08:46:59.6841501Z ##[debug]$content = [IO.File]::ReadAllText("C:\[myLocalAgent]\_work\r7\a\releasenotes.md")
2020-03-10T08:46:59.6855896Z ##[debug]# Get content of package.json for getting version value
2020-03-10T08:46:59.6870421Z ##[debug]$contentPackage = [IO.File]::ReadAllText("C:\[myLocalAgent]\_work\r7\a\package.json") | ConvertFrom-Json;
2020-03-10T08:46:59.6884843Z ##[debug]# Concat the URI
2020-03-10T08:46:59.6900257Z ##[debug]$uri = $env:WikiUri +$env:WikiPath + $($contentPackage.version)
2020-03-10T08:46:59.6916667Z ##[debug]# Convert to json for Wiki API
2020-03-10T08:46:59.6932043Z ##[debug]$data = @{content=$content;} | ConvertTo-Json;
2020-03-10T08:46:59.6947112Z ##[debug]# Set Request
2020-03-10T08:46:59.6960317Z ##[debug]$params = @{uri = "$($uri)";
2020-03-10T08:46:59.6973489Z ##[debug] Method = 'PUT';
2020-03-10T08:46:59.6986730Z ##[debug] Headers = @{Authorization = "Basic $($env:basicB64Token)" };
2020-03-10T08:46:59.7000064Z ##[debug] ContentType = "application/json";
2020-03-10T08:46:59.7013085Z ##[debug] Body = $data;
2020-03-10T08:46:59.7026111Z ##[debug]}
2020-03-10T08:46:59.7039918Z ##[debug]# Call
2020-03-10T08:46:59.7053974Z ##[debug]Invoke-WebRequest @params'
2020-03-10T08:46:59.7136093Z Generating script.
2020-03-10T08:46:59.7346195Z ##[debug]AGENT_VERSION: '2.154.3'
2020-03-10T08:46:59.7464794Z ##[debug]AGENT_TEMPDIRECTORY: 'C:\[myLocalAgent]\_work\_temp'
2020-03-10T08:46:59.7490309Z ##[debug]Asserting container path exists: 'C:\[myLocalAgent]\_work\_temp'
2020-03-10T08:46:59.8394063Z ##[debug]Leaving C:\[myLocalAgent]\_work\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.165.0\powershell.ps1.
2020-03-10T08:46:59.8447996Z ##[debug]Caught exception from task script.
2020-03-10T08:46:59.8484660Z ##[debug]Error record:
2020-03-10T08:46:59.9086805Z ##[debug]The term 'powershell.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
2020-03-10T08:46:59.9099083Z ##[debug] + CategoryInfo : ObjectNotFound: (powershell.exe:String) [], Comm andNotFoundException
2020-03-10T08:46:59.9111398Z ##[debug] + FullyQualifiedErrorId : CommandNotFoundException
2020-03-10T08:46:59.9124155Z ##[debug]
2020-03-10T08:46:59.9147270Z ##[debug]Script stack trace:
2020-03-10T08:46:59.9203751Z ##[debug]
2020-03-10T08:46:59.9225885Z ##[debug]Exception:
2020-03-10T08:46:59.9278832Z ##[debug]System.Management.Automation.CommandNotFoundException: The term 'powershell.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
2020-03-10T08:46:59.9656113Z ##[error]The term 'powershell.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
2020-03-10T08:46:59.9666068Z ##[debug]Processed: ##vso[task.logissue type=error]The term 'powershell.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
2020-03-10T08:46:59.9666747Z ##[debug]Processed: ##vso[task.complete result=Failed]
我在网上搜索过,由于文件名中的空格(我的文件名中没有空格)或引用的路径不正确(我的PowerShell是内联/自动生成的),因此引用了不正确的拼写。
会很感激任何帮助。
先谢谢你。
2条答案
按热度按时间pcww981p1#
你运行的是什么操作系统?你运行的是什么PowerShell版本?它在你的环境路径中是什么?
Windows上的PowerShell有三个可执行文件
OSX/*Nix上的PowerShell只有一个可执行文件
任何时候,如果您看到类似“术语'XXX'无法识别为cmdlet、函数、脚本文件或可操作程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。”的内容,通常总是会出现安装/配置问题,无论您尝试使用什么命令,无论操作系统版本如何。
w1e3prcc2#
Azure DevOps中的PowerShell任务出错:术语“powershell.exe”未被识别为名称
由于您正在使用您的私人代理,请检查以下内容:
首先,检查系统变量中的
Path
变量,默认情况下有%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
项,如果不存在,请将包含PowerShell.exe
的相关路径添加到Path
变量中,然后重新启动机器。其次,避免在Pipeline变量中使用“Path”:
第三,尝试使用托管代理测试它,以检查错误是否来自powershell脚本本身。
希望这能有所帮助。