简体   繁体   English

如何使 Azure devops 管道任务失败,专门针对 bash 脚本中的失败

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

相关问题 如何使 Azure devops 管道任务失败,专门针对构建步骤中的失败。yaml 文件 - bash - How to fail Azure devops pipeline task specifically for failures in build-steps.yaml file - bash 如何在 azure devops 管道中使用 arguments 运行 bash 脚本? - How to run a bash script with arguments in azure devops pipeline? Azure DevOps 管道,无法在 bash 任务中创建变量 - Azure DevOps pipeline, cannot create a variable in bash task 在 Azure Devops 中,如何在运行 shell 脚本的“Azure CLI task v.2”中使用管道变量? - In Azure Devops, how can i use pipeline variables in a “Azure CLI task v.2” running shell script? 无法访问 Azure Devops 管道 bash 脚本中的内部版本号 - Cannot access build number in Azure Devops pipeline bash script cp 命令在 Bash 中不起作用 azure devops 的构建管道中的脚本 - cp command not working in Bash Script in build pipeline of azure devops azure devops 管道 | bash 脚本在多个项目上运行 dotnet 测试 - azure devops pipeline | bash script to run dotnet test on multiple projects Bash 脚本在本地成功执行但未在 Azure Devops 管道中执行 - Bash script successfully executes locally but not in Azure Devops pipeline Azure Devops内联bash脚本子shell输出作为任务组的变量 - Azure Devops inline bash script subshell output as variable to task group Azure DevOps Pipelines 中的 bash 脚本任务如何访问服务连接? - How can a bash script task in Azure DevOps Pipelines access Service Connection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM