背景:
Jenkins 中很多项目原先并没有配置build失败触发邮件,手动配置比较费时间。
考虑使用shell脚本修改所有项目的config文件,增加邮件触发配置。
shell脚本:
1.找到jobs下所有的config文件
2.对每个文件sed替换,增加邮件触发设置。
问题:
sed 中用 sed -i "s/${var}/${var2}/g" config.xml
替换 如果变量中有<> / 等特殊字符,会报错。
Jenkins 中很多项目原先并没有配置build失败触发邮件,手动配置比较费时间。
考虑使用shell脚本修改所有项目的config文件,增加邮件触发配置。
shell脚本:
1.找到jobs下所有的config文件
2.对每个文件sed替换,增加邮件触发设置。
问题:
sed 中用 sed -i "s/${var}/${var2}/g" config.xml
替换 如果变量中有<> / 等特殊字符,会报错。
#!/bin/sh
##add email config to all project
checkWords='<reporters/>'
checkWords2=`cat context.txt`
path=/data/jenkins/jobs
##find all config
find $path -maxdepth 2 -type f -name "config.xml" > config.txt
###heck email config isExist
#cat config.txt |while read line
#do
#cat ${line} |grep -E "${checkWords}|${checkWords2}"
#cat ${line} |grep "reporters"|wc -l
#echo ${line}
#echo $checkWords
#echo $checkWords2
#sed -i "s:<reporters/>:<reporters>\n <hudson.maven.reporters.MavenMailer>\n <recipients/>\n <dontNotifyEveryUnstableBuild>false</dontNotifyEveryUnstab
leBuild>\n <sendToIndividuals>true</sendToIndividuals>\n <perModuleEmail>true</perModuleEmail>\n </hudson.maven.reporters.MavenMailer>\n </reporters>:g"
test.xml
line='/data/jenkins/jobs/alpha-picture-quality-jni/config.xml'
if [ `cat ${line} |grep "reporters"|wc -l` -eq "1" ];then
echo ${line} 1
sed -i "s:<reporters/>:<reporters>\n <hudson.maven.reporters.MavenMailer>\n <recipients/>\n <dontNotifyEveryUnstableBuild>false</dontNotifyEveryUnstab
leBuild>\n <sendToIndividuals>true</sendToIndividuals>\n <perModuleEmail>true</perModuleEmail>\n </hudson.maven.reporters.MavenMailer>\n </reporters>:g"
${line}
elif [ `cat ${line} |grep "reporters"|wc -l` -eq "4" ];then
echo ${line} 4
else
echo ${line} qita
fi
#done