Azure Pipeline PowerShell@2任务报错:需指定.ps1文件路径
PowerShell@2任务要求指定.ps1文件路径的原因
你通过标准向导创建的Azure Pipeline PowerShell@2任务配置如下:
- task: PowerShell@2 displayName: "Simple Script" inputs: targetType: filePath filePath: '$(System.DefaultWorkingDirectory)/simplescript.ps2' arguments: 'version'
运行流水线时触发错误:
##[error]Invalid file path '/home/vsts/work/1/s/simplescript.ps2' A path to a .ps1 file is required.
将文件重命名为simplescript.ps1后即可正常运行,原因在于:
- PowerShell@2任务内部内置了文件扩展名校验逻辑,仅认可
.ps1作为合法的PowerShell脚本文件后缀。这是因为.ps1是PowerShell官方规定的标准脚本扩展名,任务通过该校验确保执行的是符合规范的PowerShell脚本,避免误执行其他类型文件。 - 虽然
.ps2格式的文件内容本质上是PowerShell代码,但不在任务的合法扩展名白名单范围内,因此会触发路径无效的错误提示。
内容的提问来源于stack exchange,提问作者Eeuk
相关产品推荐
相关产品推荐

