Automating your Java project workflow with a modified Gitflow branching model

Automating your Java project workflow with a modified Gitflow branching model



Key findings



  • Gitflow is a collaborative branching model that attempts to leverage the power, speed, and ease of branching of Git. This method worked well for the situation we describe here, but others have noted that using Gitflow has its own problems.
  • The documentation on using Gitflow in posting is fuzzy at best.
  • Functions are isolated within branches. You can manage your own feature changes in isolation. This approach differs from trunk-based development, where each developer commits to mainline at least once every 24 hours.
  • Separating features using isolated branches allows you to decide which features to include in each release. The trade-off here can be complex merges.





Update Feb 13, 2019: The initial design of this article has received a lot of feedback, mostly positive and sometimes not so much. The main point of contention was our use of the term "continuous delivery" in a manual release environment. If you are part of a team that deploys hundreds of releases per day, our structure may not work for you. However, if you, like us, work in a highly regulated industry such as finance, where releases are more controllable, and you want to make the most of your branching, auto-integration, auto-hosting, and versioning capabilities, then this solution might work for you as well. as for us



, «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 is a recent graduate of Stevens Institute of Technology, where he earned his Bachelor's and Master's degrees in Computer Science. Brian currently works at Nomura as a Software Engineer in the Infrastructure Development Group. He mostly spends his day working on Spring Boot back-end services or big data pipelines using Apache Spark.




All Articles