【问题标题】:Azure Dev Ops warnings inline shell scriptAzure Devops 警告内联 shell 脚本
【发布时间】:2021-02-15 15:01:18
【问题描述】:

问题

我在 Azure Dev Ops 管道中通过 SSH 在远程计算机上运行内联 shell 脚本。根据某些情况,运行管道应引发自定义警告。

该功能有效,尽管方式非常扭曲:运行管道时,会出现警告always。更准确地说:

  • 如果条件不满足,则出现一次警告。
  • 如果满足条件,则会出现两次警告。

下面的例子应该能清楚地说明问题。

示例

假设我们有以下.yaml 管道模板。请根据您的设置调整poolsshEndpoint 设置。

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 脚本都回显到了日志中——但这只是一个假设。

问题

如何确保警告仅在满足条件时才出现在执行的管道中?

【问题讨论】:

    标签: azure-devops azure-pipelines azure-pipelines-yaml


    【解决方案1】:

    看起来像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.(似乎也进行了一些解析)...

    【讨论】:

    • 嘿!这是一个不错的技巧,但它似乎完全抑制了警告 - 这也不是我想要的。如果满足条件,我仍然希望看到警告出现。
    • 它只需要稍作修正即可工作:echo $HASHHASH"vso[task.logissue type=warning]Something is fishy..." 如果你做出改变,我可以接受你的回答 ;)
    猜你喜欢
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    相关资源
    最近更新 更多