2013-10-10 148 views
1

我创造了一个工作,在构建步骤我已经下文提到的shell脚本如何发送电子邮件在我的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 

给予詹金斯之后,该脚本执行的电子邮件需要詹金斯如果被触发条件满足。否则工作应该运行但电子邮件不应触发。

+0

是'邮件或狗或sendmail'这里命令有用吗? –

回答

0

一种方法可能是使用jenkins cli在if循环中调用另一个jenkins作业。
您可以配置其他作业,这将会触发包含特定内容的邮件。并且该工作将在您的if循环的成功部分内触发

有关jenkins CLI的更多信息,请参阅here
可能会对您有所帮助。