[英]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.