| 备注 | 修改日期 | 修改人 |
| 创建版本 | 2025-11-23 16:55:07[当前版本] | 文艺范儿 |
[root@201-jenkins game]# vim index.html #v1.0.1 [root@201-jenkins game]# git add . [root@201-jenkins game]# git commit -m "v1.0.1" #为当前仓库的代码打tag [root@201-jenkins game]# git tag -a v1.0.1 -m "v1.0.1" [root@201-jenkins game]# git tag
#推送tag到远程仓库 [root@201-jenkins game]# git push -u origin v1.0.1
查看是否有Git Parameter这个插件,如果没有安装即可。
新建项目deploy_job,选择此项目是参数化的-里面选择 Git Parameter
再添加选项参数(Choice Parameter)
再到git选项中,指定git Url和指定分支为变量
再在构建中添加执行脚本
##脚本内容
[root@201-jenkins scripts]# pwd
/home/deploy/scripts
[root@201-jenkins scripts]# ll deploy_game.sh
-rw-r--r-- 1 root root 596 11月 23 14:47 deploy_game.sh
[root@201-jenkins scripts]# cat deploy_game.sh
#!/bin/bash
CODE_DIR=$(pwd)
WEB_DIR="/home/deploy/nginx/html/"
WEB_IP="10.0.0.204"
get_code_tar(){
cd $CODE_DIR && tar zcf /opt/web-$git_version.tar.gz ./*
}
scp_code_web(){
scp /opt/web-$git_version.tar.gz $WEB_IP:$WEB_DIR
}
code_tarxf(){
ssh $WEB_IP "cd $WEB_DIR && mkdir web-$git_version && tar xf web-$git_version.tar.gz -C web-$git_version"
}
ln_html(){
ssh $WEB_IP "cd $WEB_DIR && rm -rf game && ln -s web-$git_version game"
}
main(){
get_code_tar;
scp_code_web;
code_tarxf;
ln_html;
}
if [ $action = "deploy" ];then
main
elif [ $action ="rollback" ];then
ln_html
fi
##提交并推送代码tag v1.0.2
[root@201-jenkins game]# vim index.html #v1.0.2 [root@201-jenkins game]# git add . [root@201-jenkins game]# git commit -m "v1.0.2" #为当前仓库的代码打tag [root@201-jenkins game]# git tag -a v1.0.2 -m "v1.0.2" [root@201-jenkins game]# git tag #推送tag到远程仓库 [root@201-jenkins game]# git push -u origin v1.0.2
再到jenkins页面刷新,可以看到两个tag版本号,和选择发布还是回滚