3

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!

2 Answers 2

6

After some more research I discovered this article which says that files are not automatically downloaded for deployment jobs. I added this step, and that fixed the issue!

- checkout: self

Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

forward-slashes generally do work even on windows agents; but the leading dot may be what's causing the problem
Thanks for the suggestions. I have tried both with forward and back slashes, with and without a leading dot. I am using a Windows agent, not Linux as was the issue with the other post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.