使用 Jenkins 中的 if 块自定义松弛消息

时间:2021-04-23 11:38:57

标签: jenkins slack

我需要根据特定条件通过 jenkins post build 步骤发送一条 slack 消息。我已将以下代码片段放在我的 jenkins 构建的 Slack 通知的“自定义消息”下。下面打印了 get_schedule_response.txt 的全部内容。

Here's the result for the schedule execution --------> ${FILE,path="$WORKSPACE/get_schedule_response.txt"}

仅当 get_schedule_response.txt 文件内容包含文本 SUCCESS 时,我才想发送此 slack 通知。可以吗?

1 个答案:

答案 0 :(得分:0)

使用grep命令你可以在文件get_schedule_response.txt文件中找到SUCESSS这个词

if [(grep -o "SUCCESS" "$WORKSPACE/get_schedule_response.txt"}) = "SUCCESS"];
then
#include your slack notification for success
else
#include your slack notification for success

# -o : Print only the matched parts of a matching line,

要参考 grep 命令的所有选项,请点击此链接

https://www.geeksforgeeks.org/grep-command-in-unixlinux/

相关问题