简体   繁体   中英

AzurePowerShell task cannot find filePath

I'm trying to run a PowerShell script in Azure Yaml Pipelines and I'm getting this error:

##[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) . Version 4 also does not work. 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:

- 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM