ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Git flow 自动化发布

2021-11-01 17:33:31  阅读:196  来源: 互联网

标签:Git develop plugin flow gitflow version branch 自动化 release


背景

公司使用 Git 做版本管理,使用 Jenkins 做自动化 Build 。但是在发布的时候,还是有很多人工的活。

步骤如下:

  • 在 Jenkins 上运行 release job: build develop branch 。
  • 手动填写 release version
  • (说明1)在背后,Jenkins 会做两个 commit ,一个是更新 pom 文件里的 version 为指定的版本,把 SNAPSHOT 去掉,打一个 tag ,并把这个上传到 Nexus 上。
  • (说明2)然后,另一个 commit 是更新 pom 文件里的 version number +1 ,在把 SNAPSHOT 加回去,作为下一个开发周期的分支。
  • 在发布成功后,手动将 develop 分支 merge 到 master 分支。

一次发布涉及十几个项目,每个手动 merge 一遍,还是不小的工作量。

改进

使用 Maven gitflow plugin ,可以实现自动化的发布。

前提

使用这个 plugin 的前提,是遵循 git flow 的基本使用规则。

简单概括如下:

  • origin/master存放的是【生产环境】最新的代码。
  • origin/develop存放的是【开发环境】最新的代码。
  • Feature branches 从 develop 中来,到 develop 中去。
  • Hotfix branches 从 master 中来,到 master 和 develop 中去,命名以hotfix-开头。
  • Release branches 从 develop 中来,到 develop 和 master 中去,命名以release-开头。

详情参考 -> https://nvie.com/posts/a-successful-git-branching-model/

实现

Project source: https://github.com/aleksandr-m/gitflow-maven-plugin

Maven依赖注入:

<build>
    <plugins>
        <plugin>
            <groupId>com.amashchenko.maven.plugin</groupId>
            <artifactId>gitflow-maven-plugin</artifactId>
            <version>1.16.0</version>
            <configuration>
                <!-- optional configuration -->
		    <gitFlowConfig>
                        <productionBranch>master</productionBranch>
                        <developmentBranch>develop</developmentBranch>
                        <releaseBranchPrefix>release-</releaseBranchPrefix>
                        <versionTagPrefix></versionTagPrefix>
                        <origin>origin</origin>
                    </gitFlowConfig>
            </configuration>
        </plugin>
    </plugins>
</build>

在 Jenkins 端使用 Maven 命令如下:

gitflow:release-start - Starts a release branch and updates version(s) to release version.
gitflow:release-finish - Merges a release branch and updates version(s) to next development version.
gitflow:feature-start - Starts a feature branch and optionally updates version(s).
gitflow:feature-finish - Merges a feature branch.
gitflow:hotfix-start - Starts a hotfix branch and updates version(s) to hotfix version.
gitflow:hotfix-finish - Merges a hotfix branch.

参考

标签:Git,develop,plugin,flow,gitflow,version,branch,自动化,release
来源: https://www.cnblogs.com/maxstack/p/15494305.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有