【发布时间】:2019-10-14 08:21:18
【问题描述】:
Powershell task 的 yaml 架构允许您选择 targetType: 'inline' 并在 script: input 中定义一个脚本。
但是编写多行脚本的正确格式是什么?
文档没有说明如何,并且在第一行使用管道(就像为命令行任务指定的那样)不起作用。
【问题讨论】:
标签: powershell azure-pipelines
Powershell task 的 yaml 架构允许您选择 targetType: 'inline' 并在 script: input 中定义一个脚本。
但是编写多行脚本的正确格式是什么?
文档没有说明如何,并且在第一行使用管道(就像为命令行任务指定的那样)不起作用。
【问题讨论】:
标签: powershell azure-pipelines
您可以使用竖线字符(literal Block Scalar Indicator)来定义带有换行符的多行文本块,例如您的内联脚本;比如这样:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
Write-Host "Hello world"
Write-Host "Hullo clouds"
Write-Host "Hullo sky"
【讨论】:
可以像这样使用 powershell 任务:
# Job definition etc
steps:
- powershell: |
Write-Host A
Write-Host B
Write-Host C
- task: AzureRmWebAppDeployment@4
# The rest of this task is omitted.
如果您使用powershell 而不是task: PowerShell@2,则目标类型默认为inline,您无需再次设置。
【讨论】:
可以chain PowerShell command using semicolon。所以实际上在一行上写了几个命令,用分号分隔。
(注意 Azure Pipelines 中的 5000 characters line limit。)
【讨论】: