我创建了一份工作,在构建步骤中我给出了下面提到的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中触发电子邮件。否则应该开始工作,但电子邮件不应该触发。
答案 0 :(得分:1)
看起来像是关于如何从shell脚本发送电子邮件的标准问题:请查看以下链接。
http://theos.in/shell-scripting/send-mail-bash-script/
http://www.cyberciti.biz/faq/linux-unix-bash-ksh-csh-sendingfiles-mail-attachments/
答案 1 :(得分:0)
一种方法是使用jenkins cli在if循环中调用另一个jenkins作业。
您可以配置另一个作业,该作业将触发包含特定内容的邮件。并且该工作将在if循环的成功部分内触发
有关jenkins CLI的更多信息,请访问here
可能会有所帮助。