英文:
Azure Pipeline PowerShell Script Error "A path to a .ps1 file is required"
问题
我创建了一个Azure管道,并使用标准向导创建了一个powershell@2任务。
```plaintext
- task: PowerShell@2
displayName: "简单脚本"
inputs:
targetType: filePath
filePath: '$(System.DefaultWorkingDirectory)/simplescript.ps2'
arguments: 'version'
然而,当我运行管道时,出现了错误 "##[error]Invalid file path '/home/vsts/work/1/s/simplescript.ps2' 需要一个 .ps1 文件路径。"
为什么 PowerShell@2 任务要寻找一个 .ps1 文件?
最初,我认为问题与我引用文件的方式有关,工作目录可能未设置正确。我在这个之前放了一个内联步骤,似乎确认变量被正确设置,文件路径也有效。
然后我将目标文件改名为 simplescript.ps1,它可以正常工作。
<details>
<summary>英文:</summary>
I've created an Azure pipeline and have a powershell@2 task that I created using the standard wizard.
- task: PowerShell@2
displayName: "Simple Script"
inputs:
targetType: filePath
filePath: '$(System.DefaultWorkingDirectory)/simplescript.ps2'
arguments: 'version'
however, I get an error "##[error]Invalid file path '/home/vsts/work/1/s/simplescript.ps2' A path to a .ps1 file is required." when I run the pipeline.
Why would a PowerShell@2 task look for a .ps1 file?
Initially, I assumed that the problem was related to how I referenced the file and that the working directory may not be set correctly. I've put an inline step before this one and that seems to confirm the variable is set correctly and the file path is valid.
I then renamed the target file to simplescript.ps1 and it works fine.
</details>
# 答案1
**得分**: 0
为什么 PowerShell@2 任务要查找 .ps1 文件?
所有的 PowerShell 脚本都应该具有 .ps1 扩展名。@2 指的是任务版本,与 PowerShell 版本或文件扩展名无关。
同样,AzurePowershell@5 任务应该有一个 .ps1 的 PowerShell 脚本。
<details>
<summary>英文:</summary>
> Why would a PowerShell@2 task look for a .ps1 file?
All powershell scripts should have the .ps1 extension. The @2 refers to the task version, and has nothing to do with powershell versioning or file extensions.
Similarly, the AzurePowershell@5 task should have a .ps1 powershell script.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论