【问题标题】:Customise slack message with if block in Jenkins使用 Jenkins 中的 if 块自定义松弛消息
【发布时间】:2021-04-23 23:55:56
【问题描述】:

我需要根据特定条件通过 jenkins 后期构建步骤发送一条松弛消息。我已将以下代码 sn-p 放在我的詹金斯构建的 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 通知。有可能吗?

【问题讨论】:

    标签: jenkins slack


    【解决方案1】:

    通过使用 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/

    【讨论】:

    • 抱歉耽搁了。我生病了。 jenkins 中的这行代码打印了所有内容,这也是 if 条件的一部分。它不将 if 括号代码视为条件。 Slack msg 本身看起来像: if [(grep -o "SUCCESS" "$WORKSPACE/get_schedule_response.txt"}) = "SUCCESS"]; . .别的 。 .
    猜你喜欢
    • 1970-01-01
    • 2023-02-13
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多