使用修改后的Gitflow分支模型自动执行Java项目工作流
主要发现
- Gitflow是一种协作分支模型,它试图利用Git的强大功能,速度和便捷的分支功能。这种方法在我们这里描述的情况下效果很好,但是其他人指出使用Gitflow有其自身的问题。
- 关于在发布中使用Gitflow的文档充其量是模糊的。
- 功能在分支内隔离。您可以单独管理自己的功能更改。这种方法与基于主干的开发不同,在主干开发中,每个开发人员每24小时至少要提交一次主线。
使用隔离的分支来分离功能允许您决定每个发行版中包括哪些功能。这里的权衡可能是复杂的合并。
2019年2月13日更新:本文的初始设计已收到很多反馈,大部分是正面的,有时不是很多。争论的重点是我们在手动发布环境中使用术语“连续交付”。如果您是每天部署数百个版本的团队的一员,那么我们的结构可能对您不起作用。但是,如果您像我们一样,在金融等受到严格监管的行业中工作,在该行业中发行更加可控,并且您想充分利用分支,自动集成,自动托管和版本控制功能,那么该解决方案也可能对您有效。至于我们
几年前,我在一次技术会议上,在一次名为Git的贸易展览上偶然发现了一种新奇的装置。我发现这是新一代的版本控制工具,我的第一个反应是:为什么我们需要这个,而我们已经有了SVN?那是那时。今天,开发团队正在向Git迁移,围绕中间件和插件的庞大生态系统已经出现。
Gitflow — , , Git. InfoQ, , , , . Gitflow 2010 « Git». Gitflow , , , . , , , , , .
Gitflow , , . , . — master, development, feature .., , , Snapshot, Dev, UAT, Prod ..?
, , , .
Java Maven, , . GitLab CI , Jenkins GitHub CI; Jira , IntelliJ IDEA IDE, Nexus , Ansible , .
, «» «» — , , ., . , , , « ». « », « »; , . - Thoughtworks , CI.
Gitflow
Gitflow feature . , , Git.
Git, «master»; «trunk», Git Git. Gitflow, , , .
Gitflow
Gitflow, , master «develop». develop , , , «».
, develop, master. Master — «» , , , , . - , .
develop "". , — , , ; . , , , , , "".
, ? :
Jira, . , , , master:
, «feat-», Jira. ( Jira, Epic Parent , .) , «feat-SDLC-123-add-name-field». «feat-» , CI- , . , . SDLC-123 — Jira, , .
: , , , . , , « (merge hell)».
, Snapshots
. , Sonatype Nexus. . «SNAPSHOT» semver ( ), «-SNAPSHOT» (, 1.2.0-SNAPSHOT). , «-SNAPSHOT» (, 1.2.0). Snapshot , , Snapshot, . ; , , , , Nexus.
, X, Y. , POM (, 1.2.0-SNAPSHOT). , Nexus, Nexus. , Nexus, 1.2.0-SNAPSHOT , ( , !) .
GitLab CI
, ! , ? GitLab CI, , Nexus, feat- Maven ( ), Maven ( Snapshot Nexus).
GitLab CI ( .gitlab-ci.yml) , CI / CD. , , .
GitLab CI , :
feature-build:
stage:
build
script:
- mvn clean verify sonar:sonar
only:
- /^feat-\w+$/
, , , , .
,
. IntelliJ «», ( , ) , , . ( ) Maven (, Jacoco), . IDE, , , .
[ — , , , , . , ; , -, , . , .]
Maven. Maven ( , Test-something.java Test.java, Tests.java TestCase.java). Maven verifyphase ( Maven Failsafe) . mvn verify , , . SonarQube Maven SonarQube . .
Gitflow. , , «», . , , .
, GitLab, :
SDLC - , . , . , , , , . , , Nexus , POM, , . 0.0.0-SNAPSHOT POM, .
, , , , . , , SNAPSHOT Nexus.
develop. Gitflow ; . , , ( ), () , () , , . , 1.2.0, 1.2.1, Snapshot pom 1.2.1-SNAPSHOT. , 1.2.1.
GitLab CI , ( semver , ; : \d+\.\d+\.\d+
). CI/CD POM, SNAPSHOT, (1.2.1-SNAPSHOT ).
release-build:
stage:
build
script:
- mvn versions:set -DnewVersion=${CI_COMMIT_REF_NAME}-SNAPSHOT
# now commit the version to the release branch
- git add .
- git commit -m "create snapshot [ci skip]"
- git push
# Deploy the binary to Nexus:
- mvn deploy
only:
- /^\d+\.\d+\.\d+$/
except:
- tags
[ci skip]
. , !
, CI POM, pom.xml ( , ). POM SNAPSHOT .
GitLab CI, (/^\d+\.\d+\.\d+$/
, 1.2.1) , , push. GitLab mvn deploy SNAPSHOT Nexus. Ansible , . . , , -, SNAPSHOT, SNAPSHOT Nexus SNAPSHOT .
Ansible, . , , , cron . Ansible .
, , master, Git semver , Nexus .
, GitLab CI , , . jar Ansible, GitLab CI.
master-branch-build:
stage:
build
script:
# Remove the -SNAPSHOT from the POM version
- mvn versions:set -DremoveSnapshot
# use the Maven help plugin to determine the version. Note the grep -v at the end, to prune out unwanted log lines.
- export FINAL_VERSION=$(mvn --non-recursive help:evaluate -Dexpression=project.version | grep -v '\[.*')
# Stage and commit the binaries (again using [ci skip] in the comment to avoid cycles)
- git add .
- git commit -m "Create release version [ci skip]"
# Tag the release
- git tag -a ${FINAL_VERSION} -m "Create release version"
- git push
- mvn sonar:sonar deploy
artifacts:
paths:
# list our binaries here for Ansible deployment in the master-branch-deploy stage
- target/my-binaries-*.jar
only:
- master
master-branch-deploy:
stage:
deploy
dependencies:
- master-branch-build
script:
# "We would deploy artifacts (target/my-binaries-*.jar) here, using ansible
only:
- master
. , . (Develop , .)
, , . Master GitLab, , . GitLab master, SNAPSHOT . GitLab Maven : removeSnapshot. «-SNAPSHOT» POM, runner GitLab master, , POM SNAPSHOT Nexus. UAT QA UAT. , . ( Ansible, .)
hotfix
, . , , , . Hotfix . , . , , master.
. , hotfix Nexus SNAPSHOT UAT. , , master . Master Nexus.
:
, Gitflow. . , :
- Feature . Feature , Feature, Feature,
- Feature, , Feature . — , Feature, Feature.
- , , .
- , , .
Gitflow , , , .
Gitflow Atlassian Bamboo BitBucket . .
Gitflow Maven, , , Maven Gitflow. Gitflow.
Nomura Securities . Oracle Java, Java InfoQ Java.
Brian Gardner是史蒂文斯理工学院的最新毕业生,在那里他获得了计算机科学的学士和硕士学位。Brian目前在野村证券(Nomura)担任基础设施开发组的软件工程师。他大部分时间都在使用Apache Spark从事Spring Boot后端服务或大数据管道方面的工作。