1)安装插件 “Build With Parameters”,重启 Jenkins
2)返回项目配置中心,配置 “参数化构建过程”,如下图所示:
设定操作类型和版本号(这里采用build_number)3)修改 shell 命令,如下图:
4)指定构建后的存档
5)命令
# Command
case $opt_type in
deploy)
echo "Deploy Start..."
chmod 777 /usr/local/scripts/deploy.sh
BUILD_ID=dontKillMe
sh /usr/local/scripts/deploy.sh "hello"
echo "Deploy Finish..."
;;
rollback)
echo "Rollback Start..."
chmod 777 /usr/local/scripts/rollback.sh
BUILD_ID=dontKillMe
sh /usr/local/scripts/rollback.sh "hello"
echo "Rollback Finish..."
;;
*)
;;
esac
# deploy.sh
#Stop Service
echo "$1服务正在关闭..."
kill -9 $(ps -ef|grep $1|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ') &
#Upload Jar
echo "项目Jar文件已上传部署目录..."
mv /root/.jenkins/workspace/$1/target/$1-1.0-SNAPSHOT.jar /workspace
#Start Service
#echo "授予当前用户权限"
#chmod 777 /workspace/$1
echo "$1服务正在启动..."
java -jar /workspace/$1-1.0-SNAPSHOT.jar &
# rollback.sh
#Stop Service
echo "$1服务正在关闭..."
kill -9 $(ps -ef|grep $1|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ') &
#Rollback Jar
echo "项目Jar文件正在回退上一个版本..."
cp /root/.jenkins/jobs/$1/builds/${opt_version}/archive/target$1-1.0-SNAPSHOT.jar /workspace
#Start Service
#echo "授予当前用户权限"
#chmod 777 /workspace/$1
echo "$1服务正在启动..."
java -jar /workspace/$1-1.0-SNAPSHOT.jar &
网友评论