简体   繁体   English

Azure DevOps Pipeline 任务失败但仍显示绿色(成功)

[英]Azure DevOps Pipeline task fails but still shows green (sucess)

Task is running on Node.任务在节点上运行。

Part of the yaml file for the pipeline is:管道的 yaml 文件的一部分是:

steps:
  - script: |
      #!/bin/bash
      ./plan.sh
    displayName: "example deploy"
    continueOnError: false

Now, when sometimes the./plan.sh script fails: but it still shows as a success (green tick) in the pipeline.现在,有时 ./plan.sh 脚本会失败:但它仍然在管道中显示为成功(绿色勾号)。 See below:见下文: 在此处输入图像描述

How do I make it show a "failed" red cross whenever it fails?如何让它在失败时显示“失败”的红十字?

For your script step to signal failure, you need to make the script as a whole return a non-0 exit code.为了让脚本步骤发出失败信号,您需要使脚本作为一个整体返回非 0 退出代码。 You may need some conditional logic in your script, checking the exit code from plan.sh after it returns.您可能需要在脚本中添加一些条件逻辑,在 plan.sh 返回后检查退出代码。

What you are doing now is actually calling the bash script file from PowerShell.您现在所做的实际上是从 PowerShell 调用 bash 脚本文件。 Your way of writing it cannot capture the error message.您编写它的方式无法捕获错误消息。 The correct way is as follows:正确的方法如下:

plan2.sh计划2.sh

xxx

pipeline YAML definition:管道 YAML 定义:

trigger:
- none

pool:
  vmImage: ubuntu-latest

steps:
- script: |
    bash $(System.DefaultWorkingDirectory)/plan2.sh
  displayName: "example deploy"
  continueOnError: false

Successfully get the issue:成功解决问题:

在此处输入图像描述

But usually, we use the bash task directly to run the bash script.但通常,我们直接使用 bash 任务来运行 bash 脚本。

plan.sh计划.sh

{ 
    xxx
    # Your code here.

} || { 
    # save log for exception 
    echo some error output here.
    exit 1
}

pipeline YAML definition part:管道 YAML 定义部分:

steps:
- task: Bash@3
  displayName: 'Bash Script'
  inputs:
    targetType: filePath
    filePath: ./plan.sh

Successfully get the issue:成功解决问题:

在此处输入图像描述

I was able to solve this by adding我能够通过添加来解决这个问题

set -o pipefail设置-o pipefail

In the start of the yaml file.在 yaml 文件的开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure devops 管道任务错误:Measure-Command 调用失败 - Azure devops pipeline task error : Measure-Command invocation fails Azure devops 管道作业显示成功,即使 Maven 任务失败 - Azure devops pipeline job shows success even though the Maven task is failed 在 Azure Devops Pipeline“未授权:无效的客户端 ID 或客户端密码”中,将 Docker 映像任务拉入并推送到 ACR 失败。 - Pull and Push Docker Image task to ACR fails in Azure Devops Pipeline "unauthorized: Invalid clientid or client secret." 在 azure devops 中选择发布管道中的任务 - selection of task in release pipeline in azure devops Azure DevOps - 恢复数据库的管道发布任务 - Azure DevOps - Pipeline Release Task to Restore Database Azure DevOps 发布管道每次都失败 - Azure DevOps Release Pipeline Fails Every Time Azure Devops 代理管道安装 pip 失败 - Azure Devops Agent Pipeline install pip fails Azure DevOps 管道任务等待另一个管道完成 - Azure DevOps pipeline task to wait to run for another pipeline to complete 如何在 Azure Devops 管道中的 YAML 中设置管道“任务版本” - How to set Pipeline 'Task version' in YAML in Azure Devops pipeline Azure DevOps 构建管道 - 失败的构建仍会部署到 Azure - Azure DevOps Build Pipeline - A failed build still gets deployed to Azure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM