繁体   English   中英

如何在詹金斯的外壳脚本条件下发送电子邮件

[英]How to send email on my shell script condition in jenkins

我创建了工作,并在构建步骤中给出了下面提到的shell脚本

# Shell script to monitor or watch the disk space
# It will send an email to $ADMIN, if the (free avilable) percentage 
# of space is >= 70% 
# -------------------------------------------------------------------------
# set admin email so that you can get email
# set alert level 70% is default

ALERT=70
EXCLUDE_LIST="/net|/home|devfs"
if [ "$EXCLUDE_LIST" != "" ] ; then
  df -H | grep -vE "^Filesystem|Users|${EXCLUDE_LIST}" | awk '{ print $5 " " $1 }' | while read output;
do
  #echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge $ALERT ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" > /Users/Shared/Jenkins/disk_space.txt
else
    echo "space \"$partition ($usep%)\" on $(hostname) as on $(date)" > /Users/Shared/Jenkins/space.txt
  fi
done
fi

此脚本执行后,如果条件满足,则需要以詹金斯方式触发电子邮件。 否则,作业应运行,但电子邮件不应触发。

一种方法是使用jenkins cli在if循环中调用另一个jenkins作业。
您可以配置另一个作业,该作业将触发包含某些内容的邮件。 而该工作将在if循环的成功部分内触发

可以在此处找到有关jenkins CLI的更多信息
也许这会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM