问题
我正在 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 脚本应该回显 ALL GOOD!
因为 3 不是 0。因此,不应触发警告消息。
当前行为
但是,当我在 Azure Dev Ops 中运行上述管道时,步骤日志概述显示有一个警告:
日志本身如下所示(连接详细信息被涂黑):
因此,即使代码采用 ALL GOOD!
代码路径,也会出现警告消息。我认为这是因为整个 bash 脚本都回显到日志中 - 但这只是一个假设。
问题
如何确保警告仅在满足条件时才出现在执行的管道中?
最佳答案
看起来像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. (似乎也确实发生了一些解析)...
关于azure-devops - Azure Devops 警告内联 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66210365/