[英]How to fail Azure devops pipeline task specifically for failures in bash script
I am using Azure Devops pipeline and in that there is one task that will create KVM guest VM and once VM is created through packer inside the host it will run a bash script to check the status of services running inside the guest VM.我正在使用 Azure Devops 管道,其中有一项任务将创建 KVM 来宾 VM,一旦通过主机内的打包程序创建 VM,它将运行 bash 脚本来检查来宾 VM 内运行的服务的状态。 If any services are not running or thrown error then this bash script will exit with code 3 as i have added the value in bash script as below如果任何服务未运行或抛出错误,则此 bash 脚本将以代码 3 退出,因为我已在 bash 脚本中添加了如下值
set -e设置-e
So i want the task to fail if the above bash script fails, but issue is in the same task as KVM guest VM is getting created so while booting up and shutdown it throws expected errors but i dont want this task to fail due these error but to fail it only bash scripts fails.因此,如果上述 bash 脚本失败,我希望任务失败,但问题与创建 KVM 来宾 VM 的任务相同,因此在启动和关闭时会引发预期错误,但我不希望此任务因这些错误而失败,但是失败只有 bash 脚本失败。
i have selected the option in task "Fail on Standard Error" But not sure how we can fail the task specifically for bash script error, can anyone have some suggestions on this?我已经选择了任务“标准错误失败”中的选项,但不确定我们如何才能使任务专门针对 bash 脚本错误而失败,有人对此有什么建议吗?
You can try and use exit 1
command to have the bash task failed.您可以尝试使用exit 1
命令使 bash 任务失败。 And it is often a command you'll issue soon after an error is logged.它通常是您在记录错误后很快就会发出的命令。
Additionally, you also may use logging commands to customized a error message.此外,您还可以使用日志记录命令来自定义错误消息。 Kindly refer to the sample below.请参考下面的示例。
#!/bin/bash
echo "##vso[task.logissue type=error]Something went very wrong."
exit 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.