【问题标题】:AzurePowerShell task cannot find filePathAzure PowerShell 任务找不到文件路径
【发布时间】:2022-01-06 14:47:18
【问题描述】:

我正在尝试在 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

文件被推送到触发构建的分支的 repo。我还尝试使用$(Pipeline.Workspace)$(Build.SourcesDirectory) 显式引用路径。版本 4 也不起作用。根据the docs,这应该可以工作!

【问题讨论】:

    标签: azure azure-devops azure-pipelines azure-powershell azure-yaml-pipelines


    【解决方案1】:

    经过更多研究,我发现this article 表示不会为部署作业自动下载文件。我添加了这一步,解决了这个问题!

    - checkout: self

    【讨论】:

      【解决方案2】:

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

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

      这似乎是原因。

      这里也有类似的问题。看起来这取决于您使用的是 Windows 还是 linux 代理:cannot locate file in azure devops pipeline

      【讨论】:

      • 正斜杠通常确实在 Windows 代理上也有效;但前导点可能是导致问题的原因
      • 感谢您的建议。我尝试过使用正斜杠和反斜杠,有无前导点。我使用的是 Windows 代理,而不是 Linux,因为其他帖子的问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 2019-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-25
      相关资源
      最近更新 更多