如果条件,如何编写Inline PowerShell@2任务脚本?
我有一个具有这样的任务的YAML管道:
- task: PowerShell@2
displayName: Restart my service
inputs:
targetType: 'inline'
script: |
$service = Get-Service | Where-Object{$_.DisplayName -like "My Service"}
if($service)
{
Write-host $service.Name " service is restarting."
Restart-Service $service
}
但是,最后一个“}”被标记为“无法读取块映射条目”的错误。我认为它试图将某些脚本读为管道内容,而不会将其视为脚本的一部分。我如何将其作为整个内联脚本接受?
I've got a yaml pipeline with a task like this:
- task: PowerShell@2
displayName: Restart my service
inputs:
targetType: 'inline'
script: |
$service = Get-Service | Where-Object{$_.DisplayName -like "My Service"}
if($service)
{
Write-host $service.Name " service is restarting."
Restart-Service $service
}
However, the last '}' is being flagged as an error with "cannot read a block mapping entry". I assume that it's trying to read some of the script as pipeline stuff and doesn't consider it part of the script. How do I get this to be accepted as the whole inline script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来这是一个缩进的问题。我知道它可以处理以下内容:
Looks like this was an indenting issue. I got it to work with the following: