Azure Devops Piepeline - Yaml Powershell Script Path

5.8k views Asked by At

I would like to ask you if someone knows how to create a correct path to powershell in Azure Devops Pipeline Yaml Syntax.

How looks like my YAML (Currently):

trigger:
- develop

pool:
  vmImage: 'ubuntu-latest'

steps:

- task: PowerShell@2
  inputs:
    filePath: './scripts/script.ps1'

How looks like my directory:

enter image description here

What kind of path returns the pipeline:

Get-Content: /home/vsts/work/1/s/scripts/script.ps1:12

What kind of error returns the pipeline:

##[error]PowerShell exited with code '1'.

3

There are 3 answers

0
stacktracerr On BEST ANSWER

Correct answer:

- task: PowerShell@2
  inputs:
    filePath: '$(Agent.BuildDirectory)/s/scripts/script.ps1'
0
DreadedFrost On

Would need to see how your publish task looks like and what the relative path looks like. Try adding -powershell Get-ChildItem -Path $(Build.ArtifactStagingDirectory) -recurse This will list out all the paths so you can see what the full path to your script is.

0
Hugh Lin On

I would like to ask you if someone knows how to create a correct path to powershell in Azure Devops Pipeline Yaml Syntax.

It's not that PS can't find your script, instead the error message indicates there's something wrong with the line12 in your xx.ps1 file.

I can't locate the issue until you share the content of the script here. My suggestion is that you should run the pipeline again with System.Debug=true to get the detailed error message, you should get the hint there.