AzurePowerShell 任务找不到 filePath

AzurePowerShell task cannot find filePath

提问人:Rachel 提问时间:11/30/2021 更新时间:11/30/2021 访问量:2920

问:

我正在尝试在 Azure Yaml Pipelines 中运行 PowerShell 脚本,并收到此错误:

##[error]The term 'D:\a\1\s\myPowershellFile.ps1' 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.

法典:

jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: $(myEnvironment)
    pool:
      vmImage: 'windows-latest'

    strategy:
      runOnce:
        deploy:
          steps:          
          - task: AzurePowerShell@5
            displayName: 'Run Powershell script'
            inputs:
              azureSubscription: $(azureConnectionName)
              scriptType: filePath
              scriptPath: './myPowershellFile.ps1'
              azurePowerShellVersion: latestVersion

该文件将推送到触发生成的分支的存储库。我还尝试过用 和 显式引用路径。版本 4 也不起作用。根据文档,这应该有效!$(Pipeline.Workspace)$(Build.SourcesDirectory)

azure-devops azure-yaml-pipelines

评论


答:

0赞 Rimaz Mohommed 11/30/2021 #1

忍不住注意到,但您已使用正斜杠“/”作为文件路径的分隔符,而不是像您在 azure 文档中指向的示例中那样使用反斜杠“\”

- task: AzurePowerShell@5
  inputs:
    azureSubscription: my-arm-service-connection
    scriptType: filePath
    scriptPath: $(Build.SourcesDirectory)\myscript.ps1

这看起来像是原因。

这里也有类似的问题。看起来这取决于您使用的是 Windows 还是 Linux 代理:无法在 Azure DevOps 管道中找到文件

评论

0赞 Vince Bowdren 11/30/2021
即使在 Windows 代理上,正斜杠通常也有效;但前导点可能是导致问题的原因
0赞 Rachel 11/30/2021
谢谢你的建议。我尝试过正斜杠和反斜杠,有和没有前导点。我使用的是 Windows 代理,而不是 Linux,因为另一篇文章的问题也是如此。
5赞 Rachel 11/30/2021 #2

经过进一步的研究,我发现了这篇文章,其中说文件不会自动下载用于部署作业。我添加了这一步,解决了这个问题!

- checkout: self