欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

项目发布脚本

程序员文章站 2022-07-09 13:20:46
...
原理:两个svn,一个研发svn,用于研发时使用,一个发布svn用于产品发布。实现时把研发svn的内容编译打包,发布到发布svn。

脚本release.sh代码如下
base_dir=`dirname $0`
read_conf(){
	dir=`dirname $0`
	echo `cat $dir/release.conf |grep "^[^#]"|grep -w $1|tr -s "[\t ]" " "|awk -F"=" '{print $2}'`
}
echo BASEDIR=$base_dir
#源码目录
source_dir=$base_dir/source
#发布目录
release_dir=$base_dir/release

source_svn_url=`read_conf "source_svn_url"`
release_svn_url=`read_conf "release_svn_url"`
target_dir=`read_conf "target_dir"`

echo "SVN CONFIG"
echo "reource url="$source_svn_url
echo "release url="$release_svn_url

if [ ! -d $source_dir ]
then
	echo "checkout source"
	echo $source_svn_url $source_dir
	svn=`svn co $source_svn_url $source_dir`
	echo "checkout source over"
else
	echo "update source"
	svn up $source_dir|grep "^D"
fi

if [ ! -d $release_dir ]
then
	echo "Checkout release"
	svn=`svn co $release_svn_url $release_dir`
	echo "Checkout release over"
else
	echo "update release-source"
	svn up ${release_dir}|grep "^D"
fi
echo "Building ..."
mvn -f  $source_dir/pom.xml clean package
echo "Build over"

echo "Copy release"
echo "cp -rf "$source_dir"/target/"${target_dir}"/*" $release_dir
cp -rf $source_dir/target/${target_dir}/* $release_dir
echo "Copy Over"
cd $release_dir
pwd
submitList=`svn st |grep "^?"|awk '{print $2}'`
if [ -n "$submitList" ]
then
	svn st|grep "^?"
	echo -e "Whether to add all files?[Y/N]\c";
	read submit
	submit=`echo $submit`|tr -s "Y" "y"
	if [ "$submit" == "Y" ] || [ "$submit" == "y" ]
	then
		svn add $submitList
	fi
fi
echo "Check release status"
svn st
commitList=`svn st`
svn ci -m "submit release" 


对应配置release.conf
source_svn_url=svn://develop_IP/A/server/trunk
release_svn_url=svn://release_IP/release/A/server
target_dir=A


题外话:
1、脚本中判断字符串长度是否为空,一定要用""引起来,否则会出错
if [ -n "$submitList" ]


2、mvn用于产品发布还是很方便,约定优于配置是个好东西!
相关标签: 脚本 发布