The yaml schema for a Powershell task allows you to select targetType: 'inline' and define a script in the script: input.
But what is the correct format for writing a script with more than one line?
The docs don't specify how, and using a pipe on line one (like is specified for the Command Line task) does not work.
You can use the pipe character (the literal Block Scalar Indicator) to define a multi-line block of text with newline characters such as your inline script; for example like this:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
Write-Host "Hello world"
Write-Host "Hullo clouds"
Write-Host "Hullo sky"
It is possible to just use the powershell task like this:
# Job definition etc
steps:
- powershell: |
Write-Host A
Write-Host B
Write-Host C
- task: AzureRmWebAppDeployment@4
# The rest of this task is omitted.
If you use powershell
instead of task: PowerShell@2
the target type defaults to inline
and you don't need to set it again.
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