您的位置:首页 > 运维架构 > Shell

项目需要,shell脚本自动化替换文档内容,并提交代码 3ff8

2017-10-31 10:53 323 查看
项目需要,shell脚本自动化替换文档内容,并提交代码

#!/bin/bash

if [ ! $commitTag ]; then
echo "commitTag IS NULL"
exit
fi

echo ".........................push code start ..............................."
#root根目录
#rootPath=/Users/user/git/myelong
rootPath=/home/hudson/workspace
#前端最后一次提交commit,参入传入
#commitTag=316cb08031dc96c185d35d934d0264374255d95b
#后端项目空壳分支,由CI系统传入
#branch=b171102

#定义文件模版路径,即各个需要替换前端资源的模版文件路径
templatePath=$rootPath'/h5-hotelwxqb-web/src/main/resources/template'
#定义文件产出路径,即最终提交git的文件路径
outputPath=$rootPath'/h5-hotelwxqb-web/src/main/resources/config'

#从git上拉项目到本地,前端项目和后端项目都需要拉下来
cd $rootPath
#拉前端项目
git clone http://code.corp.elong.com/xy-team/hotelfx-static-resource-reference.git cd hotelfx-static-resource-reference
git init
git checkout $commitTag

#前端首页js代码文本
indexJSTxt=$(cat index.js)
#前端列表页js代码文本
listJsTxt=$(cat list.js)
#前端快速预定列表页js代码文本
flistJsTxt=$(cat flist.js)
#前端详情页js代码文本
detailJsTxt=$(cat detail.js)
#前端订单填写页js代码文本
createOderJsTxt=$(cat createorder.js)

#拉后端项目
cd $rootPath
git clone git@code.corp.elong.com:h5-website/h5-hotelwxqb-web.git
cd h5-hotelwxqb-web
git init
git checkout $branch
git pull

#替换首页前端资源
replace_index(){
#定义本地文件路径
sourceFile=$templatePath/index.txt
destFile=$outputPath/spamvtbody2_alpha.txt
destFile2=$outputPath/spamvtbody2_beta.txt
#复制本地文件模版文件,修改目标文件内容
cat $sourceFile > $destFile
echo $indexJSTxt >> $destFile
cp $destFile $destFile2
}

#替换列表页前端资源
replace_list(){
#从本地列表页模版文件替换前端资源路径,生成新列表页配置文件
sourceFile=$templatePath/list.txt
sourceFootFile=$templatePath/foot.txt
destFile=$outputPath/webapp-config-list.xml
#复制本地文件模版文件,修改目标文件内容
cat $sourceFile > $destFile
echo $listJsTxt >> $destFile
cat $sourceFootFile >> $destFile
}

#替换快速预定前端资源
replace_flist(){
#从本地列表页模版文件替换前端资源路径,生成新列表页配置文件
sourceFile=$templatePath/flist.txt
sourceFootFile=$templatePath/foot.txt
destFile=$outputPath/webapp-config-flist.xml
#复制本地文件模版文件,修改目标文件内容
cat $sourceFile > $destFile
echo $flistJsTxt >> $destFile
cat $sourceFootFile >> $destFile
}

#替换详情页前端资源
replace_detail(){
#从本地详情页模版文件替换前端资源路径,生成新详情页配置文件
sourceFile=$templatePath/detail.txt
sourceFootFile=$templatePath/foot.txt
destFile=$outputPath/webapp-config-detail.xml
#复制本地文件模版文件,修改目标文件内容
cat $sourceFile > $destFile
echo $detailJsTxt >> $destFile
cat $sourceFootFile >> $destFile
}

#替换订单填写页前端资源
replace_createorder(){
#从本地订单填写页模版文件替换前端资源路径,生成新订单填写页配置文件
sourceFile=$templatePath/createorder.txt
sourceFootFile=$templatePath/foot.txt
destFile=$outputPath/webapp-config-createorder.xml
#复制本地文件模版文件,修改目标文件内容
cat $sourceFile > $destFile
echo $createOderJsTxt >> $destFile
cat $sourceFootFile >> $destFile
}

#替换程序里的各个页面前端资源代码
replace_index
replace_list
replace_flist
replace_detail
replace_createorder

#代码提交到git上
git add -A
git commit -am 'update web script '$branch
#git pull
git push origin $branch
echo ".........................push code end ..............................."

#删除前端资源项目
cd $rootPath
rm -rf H5_JAVA_GIT_HOTELWXQB_WEB
mv h5-hotelwxqb-web H5_JAVA_GIT_HOTELWXQB_WEB
rm -rf hotelfx-static-resource-reference
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: