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

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

Azure Pipeline PowerShell Script Error "A path to a .ps1 file is required"

问题

  1. 我创建了一个Azure管道,并使用标准向导创建了一个powershell@2任务。
  2. ```plaintext
  3. - task: PowerShell@2
  4. displayName: "简单脚本"
  5. inputs:
  6. targetType: filePath
  7. filePath: '$(System.DefaultWorkingDirectory)/simplescript.ps2'
  8. arguments: 'version'

然而,当我运行管道时,出现了错误 "##[error]Invalid file path '/home/vsts/work/1/s/simplescript.ps2' 需要一个 .ps1 文件路径。"

为什么 PowerShell@2 任务要寻找一个 .ps1 文件?

最初,我认为问题与我引用文件的方式有关,工作目录可能未设置正确。我在这个之前放了一个内联步骤,似乎确认变量被正确设置,文件路径也有效。

然后我将目标文件改名为 simplescript.ps1,它可以正常工作。

  1. <details>
  2. <summary>英文:</summary>
  3. 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'
  1. 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.
  2. Why would a PowerShell@2 task look for a .ps1 file?
  3. 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.
  4. I then renamed the target file to simplescript.ps1 and it works fine.
  5. </details>
  6. # 答案1
  7. **得分**: 0
  8. 为什么 PowerShell@2 任务要查找 .ps1 文件?
  9. 所有的 PowerShell 脚本都应该具有 .ps1 扩展名。@2 指的是任务版本,与 PowerShell 版本或文件扩展名无关。
  10. 同样,AzurePowershell@5 任务应该有一个 .ps1 PowerShell 脚本。
  11. <details>
  12. <summary>英文:</summary>
  13. &gt; Why would a PowerShell@2 task look for a .ps1 file?
  14. 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.
  15. Similarly, the AzurePowershell@5 task should have a .ps1 powershell script.
  16. </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:

确定