azure-devops - Azure Devops 警告内联 shell 脚本

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

问题

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

该功能可以正常工作,尽管方式非常扭曲:运行管道时,警告总是出现。更准确地说:

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

下面的示例应该可以清楚地说明该问题。

示例

假设我们有以下 .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 中运行上述管道时,步骤日志概述显示有一个警告:

Step Log Overview

日志本身如下所示(连接详细信息被涂黑):

enter image description here

因此,即使代码采用 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/

相关文章:

c# - 如何在 VSIX 扩展中处理 VSTS 凭据

azure - 发布管道 - 在 docker 阶段之间共享工件

docker - 为什么在 azure 管道上拉取基础镜像需要花费极长的时间?

azure - 如何在Azure DevOps管道池中请求多台代理机器?

Visual Studio Team Services 中的 Git,Visual Studio 2012 项目 - 无法从构建部署

Azure SDK 在托管 VS2017 VSTS 构建代理上不可用?

azure-devops - Azure DevOps 管道 kubectl 任务命令 : rollout unavailable

azure - Azure YAML 管道出现错误无法完成部署

azure-devops - 如何通过 CredentialProvider.VSS.exe 清除凭据缓存

Azure ML 工作区 : how to publish pipeline to existing endpoint instead of creating new