自动化编译shell脚本_jenkins

为了实现我们的应用自动编译、组织版本、设置md5值、上传编译包、打基线等操作。

自动化编译shell脚本:

export LC_CTYPE="zh_CN.UTF-8"
#输入参数——发布版本号设定<编译时根据实际情况改动>
relversion=x.y.z
#输入参数——代码库的测试基线路径设定<需改动>
buildbaselinepath=svn://xxxxxxxxxxxxxxxxxxxx
#输入参数——发布的svn路径设定<需改动>
relpath=/usr/local/xxx/yyy/zzz
#设置服务名
JOB_SERVER_NAME=xxx
#获取系统日期赋给临时变量timeout
timeout=$(date +%Y%m%d%H%M%S)
#读取svn的log信息写入到临时文件
svn log -l1 $SVN_URL >/usr/local/temp/svnlog
#获取svn的log版本号

cd /usr/local/temp

svnversion=$(cat svnlog |while read line; do echo $line; done)

svnversion=${svnversion%%|*}
svnversion=${svnversion#*r}

#获取svn的bugid号
bugid=`grep bugid:    svnlog  | awk -F:  '{print $NF}'`

#调用maven命令执行编译操作<编译时根据实际项目改动>
cd $WORKSPACE/
mvn clean install -U -Dmaven.test.skip=true package dependency:copy-dependencies -DoutputDirectory=./target/lib

#在svn中创建以版本号命名的目录
cd $relpath
svn update
mkdir -p $relversion/apps

#输出元数据到xml文件中
cd $relpath/$relversion/apps
rm -rf $WORKSPACE/Metadata.xml
md5sum $WORKSPACE/xxxxxx/*.war>/SCM/build/jenkins_package/md5temp
cd /SCM/build/jenkins_package
tempmd5value=$(cat md5temp|while read line; do echo $line; done)
getmd5value=${tempmd5value% *}
sh -x /SCM/build/jenkins_package/jenkinsPackage.sh $WORKSPACE/xxxxxx WEB $relversion $getmd5value $timeout $svnversion $SVN_URL $bugid

#组织版本
#sh -x /SCM/build/java_standard/java_standard.sh $WORKSPACE $JOB_SERVER_NAME $relpath/$relversion/apps  $relversion
mkdir $relpath/$relversion/apps/$JOB_SERVER_NAME
cp $WORKSPACE/xxxxxx/target/*.war $relpath/$relversion/apps/$JOB_SERVER_NAME
cp $WORKSPACE/xxxxxx/yyyyyy $relpath/$relversion/apps/$JOB_SERVER_NAME

#压缩编译包,并且删除原目录
cd $relpath/$relversion/apps 
tar -zcvf ./$JOB_SERVER_NAME.tar.gz ./$JOB_SERVER_NAME
rm -rf ./$JOB_SERVER_NAME

#提交编译包到svn
cd $relpath
svn add * --force
svn commit -m "BuildTime:$timeout,bugidnum:$bugid at svnversion:$svnversion SVN_URL:$SVN_URL"

#创建测试基线
svn cp -r $svnversion $SVN_URL $buildbaselinepath/$timeout -m "BuildTime:$timeout,bugidnum:$bugid at svnversion:$svnversion BugID:zzznumber"

你可能感兴趣的:(SCM理论)