Azure Pipeline PowerShell脚本错误:“需要一个.ps1文件的路径”

huangapple go评论48阅读模式
英文:

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&#39;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 &quot;##[error]Invalid file path &#39;/home/vsts/work/1/s/simplescript.ps2&#39;  A path to a .ps1 file is required.&quot; 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&#39;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>

&gt; 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>



huangapple
  • 本文由 发表于 2023年5月15日 15:17:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76251696.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定