我在 Azure Dev Ops 管道中通过 SSH 在远程机器上运行内联 shell 脚本。根据某些条件,运行管道应该会抛出自定义警告。
该功能有效,尽管方式非常复杂:运行管道时,警告总是出现。更准确地说:
下面的例子应该清楚地说明了这个问题。
假设我们有以下 .yaml
管道模板。请根据您的设置调整 pool
和 sshEndpoint
设置。
pool: 'Default'
steps:
- checkout: none
displayName: Suppress regular checkout
- task: SSH@0
displayName: 'Run shell inline on remote machine'
inputs:
sshEndpoint: 'user@machine'
runOptions: inline
inline: |
if [[ 3 -ne 0 ]]
then
echo "ALL GOOD!"
else
echo "##vso[task.logissue type=warning]Something is fishy..."
fi
failOnStdErr: false
因此,上面的 bash 脚本应该 echo ALL GOOD!
as 3 is not 0。因此,不应触发警告消息。
但是,当我在 Azure Dev Ops 中运行上述管道时,步骤日志概述说有一个警告:
日志本身看起来像这样(连接细节被涂黑):
因此,即使代码采用 ALL GOOD!
代码路径,也会出现警告消息。我认为这是因为整个 bash 脚本都回显到日志中 - 但这只是一个假设。
如何确保警告仅在满足条件时才出现在执行的管道中?
答案 0 :(得分:2)
看起来像 the SSH task logs the script to the console prior to executing it。您可能会欺骗日志解析器:
HASHHASH="##"
echo $HASHHASH"vso[task.logissue type=warning]Something is fishy..."
I'd consider it a bug that the script is appended to the log as-as. I've filed an issue.(似乎也进行了一些解析)...