I'm working on a migration from the classic build system (task definition in Azure Devops) to a yaml build definition and running in the following error. I was able to break down the error while executing the PowerShell script and identfied a problem with the syntax in yaml file.
I use the PowerShell inline step like bellow:
name: 1.1$(Rev:.r)
jobs:
- job: build
steps:
- task: PowerShell@2
displayName: 'Test'
inputs:
targetType: 'inline'
script: '$var1 = "valueVar1"
$var2 = "valueVar2"'
When I run the command I#m getting the following error in Azure Devops.
2019-12-07T18:39:15.3306239Z At D:\A\01\_temp\298966df-c117-432b-b4c1-17b4ece9d7f4.ps1:2 char:21
2019-12-07T18:39:15.3306715Z + $var1 = "var1Value" $var2 = "var2Value"
2019-12-07T18:39:15.3306784Z + ~~~~~
2019-12-07T18:39:15.3306847Z Unexpected token '$var2' in expression or statement.
2019-12-07T18:39:15.3307001Z + CategoryInfo : ParserError: (:) [], ParseException
2019-12-07T18:39:15.3307719Z + FullyQualifiedErrorId : UnexpectedToken
2019-12-07T18:39:15.3308055Z
2019-12-07T18:39:15.4085556Z ##[error]PowerShell exited with code '1'.
It looks like that I connot use a line breaks in the yaml Powershell inline definition.
should be done like so:
script: |
$var1 = "valueVar1"
$var2 = "valueVar2"
would work the same with any inline task (cmd\bash\pwsh).
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/command-line?view=azure-devops&tabs=yaml#example
in fact you can just do this:
steps:
- powershell: |
$var1 = "valueVar1"
$var2 = "valueVar2"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With