简体   繁体   English

AzurePowerShell 任务找不到文件路径

[英]AzurePowerShell task cannot find filePath

I'm trying to run a PowerShell script in Azure Yaml Pipelines and I'm getting this error:我正在尝试在 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.

Code:代码:

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

The file is pushed out to the repo for the branch that is triggering the build.该文件被推送到触发构建的分支的存储库。 I've also tried referencing the path explicitly with $(Pipeline.Workspace) and $(Build.SourcesDirectory) .我还尝试使用$(Pipeline.Workspace)$(Build.SourcesDirectory)显式引用路径。 Version 4 also does not work.版本 4 也不起作用。 According to the docs this should be working!根据文档,这应该可以工作!

Couldn't help noticing but you have used the forward slash "/" as the seperator for the filepath instead of a back-slash "\" like in the example you are pointing to in the azure docs:不禁注意到,但您使用正斜杠“/”作为文件路径的分隔符,而不是像您在 azure 文档中指向的示例中的反斜杠“\”

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

This looks like the reason why.这似乎是原因。

There is a similar issue here.这里有一个类似的问题。 looks like it depends on whether you are using a windows or linux agent: cannot locate file in azure devops pipeline看起来这取决于您使用的是 windows 还是 linux 代理: 在 azure devops 管道中找不到文件

After some more research I discovered this article which says that files are not automatically downloaded for deployment jobs.经过更多研究后,我发现这篇文章说部署作业不会自动下载文件。 I added this line, and that fixed the issue!我添加了这一行,这解决了问题!

- checkout: self

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AzurePowershell 任务找不到 Profile.ps1 - AzurePowershell Task Cannot Find Profile.ps1 如何修复 AzurePowerShell 管道任务中的语法错误? - How to fix the syntax error in AzurePowerShell pipeline task? 通过 Azure DevOps AzurePowershell@5 任务创建新容器的问题 - Issue with Creating New Container Through Azure DevOps AzurePowershell@5 Task 在 DownloadBuildArtifact 任务中找不到下载的工件 - Cannot find downloaded artifact in DownloadBuildArtifact task AzurePowershell Get-AzureSubscription缺少一个订阅 - AzurePowershell Get-AzureSubscription one subscription is missing 在 Azure 模板存储库中,有没有办法为 azure 任务“pythonScript”的 filePath 参数提及存储库? - In Azure templates repository, is there a way to mention repository for a filePath parameter of azure task 'pythonScript'? AzurePowerShell@4 - 无法在 azure 管道上执行 powershell 命令 - AzurePowerShell@4 - powershell commands fail to execute on azure pipeline 使用AzurePowershell全局检查Azure SQL Server名称是否存在 - Globally check for existence of Azure SQL Server name with AzurePowershell Azure Data Factory V2 - 无法将通配符文件名与动态内容文件路径组合在一起。 是否有数据库(ADB)解决方案或其他ADF解决方案? - Azure Data Factory V2 - Cannot combine wildcard filenames with dynamic content filepath. Is there a databricks (ADB) solution or another ADF solution? 找不到任务“功能:主机启动” - Could not find the Task 'func : host start'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM