jenkins根据tag构建

axing
2025-08-02 / 0 评论 / 1 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2025年08月01日,已超过22天没有更新,若内容或图片失效,请留言反馈。

一、发布与回滚思路

正常功能发布时,是基于master分支发布的,所以我在成功发布后,会将当时的master分支自动打上tag,当需要回滚时,则基于tag分支进行发布即可。

mdszrfls.png

二、安装配置Git Parameter
2.1安装插件

要想出现tag模式的参数,需要安装git Parameter 插件,在Jenkins的Manage Jenkins→Plugins→Available Plugins 中安装

mdszsci9.png
2.2验证

安装完成后在项目的配置页的This project is parameterized 中可以看到选项

mdt02ntn.png
2.3仓库添加tag

初始化仓库,添加tag并提交
root@k8s-03:~/vue3_vite_element-plus# git config --global user.name "xing"
root@k8s-03:~/vue3_vite_element-plus# git config --global user.email "7902731@qq.com"
root@k8s-03:~/vue3_vite_element-plus# git config --global --list
user.name=xing
user.email=7902731@qq.com
root@k8s-03:~/vue3_vite_element-plus# git tag -a v1.0 -m "1.0版本"
root@k8s-03:~/vue3_vite_element-plus# git tag -l
v1.0
root@k8s-03:~/vue3_vite_element-plus# git push origin v1.0
Username for 'http://192.168.30.181': xing
Password for 'http://xing@192.168.30.181': 
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 160 bytes | 160.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
To http://192.168.30.181/xing/vue3_vite_element-plus.git
 * [new tag]         v1.0 -> v1.0
修改部分代码,并提交新版本。
root@k8s-03:~/vue3_vite_element-plus# ls
Dockerfile  Jenkinsfile  package.json  README.md   src   vite.config.mjs
index.html  nginx.conf   public        screenshot  test  webstorm.config.js
root@k8s-03:~/vue3_vite_element-plus# vi Dockerfile 
root@k8s-03:~/vue3_vite_element-plus# git commit -m "更新至v2" .
[master 636d69b] 更新至v2
 1 file changed, 2 insertions(+), 1 deletion(-)
root@k8s-03:~/vue3_vite_element-plus# git tag -a v2.0 -m "2.0版本呢"
root@k8s-03:~/vue3_vite_element-plus# git tag -l
v1.0
v2.0
root@k8s-03:~/vue3_vite_element-plus# git push origin v2.0
Username for 'http://192.168.30.181': xing
Password for 'http://xing@192.168.30.181': 
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 423 bytes | 423.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0), pack-reused 0
To http://192.168.30.181/xing/vue3_vite_element-plus.git
 * [new tag]         v2.0 -> v2.0
root@k8s-03:~/vue3_vite_element-plus# 
查看gitlab tag信息,发现已经有v1.0,v2.0tag

mdt0u5lu.png

三、使用tag变量发布
3.1发布最新版本

生成pipeline,指定分支为${tag}
root@k8s-03:~/vue3_vite_element-plus# git ls-remote --tags origin
Username for 'http://192.168.30.181': xing
Password for 'http://xing@192.168.30.181': 
3afadbd4e09f012ec0cb89e4cae667f8564ba5fa    refs/tags/v1.0
a934816659500449a9413148e69d113faf5cccea    refs/tags/v1.0^{}
cf126d51958d9ed649b6b73e0f90929c6ac58694    refs/tags/v2.0
636d69bff7fb45b6732e977fdeee56c3628a2dcc    refs/tags/v2.0^{}

mdt1dozj.png

整体思路就是发布后就会有tar版本,如果有问题马上可以回滚到稳定的版本

mdt1eo0s.png
mdt1f2s1.png

0

评论 (0)

取消