按版本发布

  1. 安装git parameter plugin插件
  2. 任务配置中勾选<参数化构建>
  3. 选择git parameter
  4. 创建变量名 release(自定义)
  5. 选择发布类型:
    tag:按标签发布
    branch:按分支发布
    Revison:按修订发布

  1. 安装git parameter plugin插件
    自动化部署之maven项目按版本发布

修改pom.xml中的版本改为v1.0

[[email protected] testing]# vim pom.xml 

<version>v1.0</version>

[[email protected] testing]# git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   pom.xml
#
no changes added to commit (use "git add" and/or "git commit -a")
[[email protected] testing]# git add .
[[email protected] testing]# git commit -m "v1.0"
[master eed5815] v1.0
 1 file changed, 1 insertion(+), 1 deletion(-)
[[email protected] testing]# git push origin master
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 281 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To [email protected]192.168.56.11:java/Java.git
   37d2bd1..eed5815  master -> master

自动化部署之maven项目按版本发布

给Java项目中的版本修改后打上标签
自动化部署之maven项目按版本发布

此时我们再修改

[[email protected] testing]# vim src/main/java/com/ghz/testweb/App.java 
package com.ghz.testweb;

/**
 * Hello world!
 *
 */
public class App
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World! i am guo2 v1.0" );
    }
}
[[email protected] testing]# git add .
[[email protected] testing]# git commit -m "featrue1"
[master 6402300] featrue1
 1 file changed, 1 insertion(+), 1 deletion(-)
[[email protected] testing]# git push origin master
Counting objects: 17, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (9/9), 565 bytes | 0 bytes/s, done.
Total 9 (delta 2), reused 0 (delta 0)
To [email protected]192.168.56.11:java/Java.git
   eed5815..6402300  master -> master

自动化部署之maven项目按版本发布

此时进行构建,由于版本修改了,会报错:
自动化部署之maven项目按版本发布

但是我们每次进行版本的修改后如果都去修改excute shell就显得太麻烦

  1. 任务配置中勾选<参数化构建>
    3.选择git parameter
  2. 创建变量名 release(自定义)
    自动化部署之maven项目按版本发布

修改源码管理
自动化部署之maven项目按版本发布

自动化部署之maven项目按版本发布

  1. 选择发布类型:
    tag:按标签发布
    自动化部署之maven项目按版本发布

6.对代码进行多次修改,并提交

然后再代码库中对提交进行tag标记

再在jenkins中查看,即可按照不同的版本进行构建,如图:
自动化部署之maven项目按版本发布