Automatisieren Sie Ihren Java-Projektworkflow mit einem modifizierten Gitflow-Verzweigungsmodell

Automatisieren Sie Ihren Java-Projektworkflow mit einem modifizierten Gitflow-Verzweigungsmodell



Wichtigste Ergebnisse



  • Gitflow ist ein kollaboratives Verzweigungsmodell, das versucht, die Leistung, Geschwindigkeit und Einfachheit der Verzweigung von Git zu nutzen. Diese Methode hat für die hier beschriebene Situation gut funktioniert, aber andere haben festgestellt, dass die Verwendung von Gitflow ihre eigenen Probleme hat.
  • Die Dokumentation zur Verwendung von Gitflow beim Posten ist bestenfalls unscharf.
  • Funktionen sind innerhalb von Zweigen isoliert. Sie können Ihre eigenen Funktionsänderungen isoliert verwalten. Dieser Ansatz unterscheidet sich von der trunkbasierten Entwicklung, bei der sich jeder Entwickler mindestens alle 24 Stunden zur Hauptleitung verpflichtet.
  • Durch das Trennen von Features mithilfe isolierter Zweige können Sie entscheiden, welche Features in jeder Version enthalten sein sollen. Der Kompromiss hier kann komplexe Zusammenschlüsse sein.





Update 13. Februar 2019: Das ursprüngliche Design dieses Artikels hat viele Rückmeldungen erhalten, meistens positiv und manchmal nicht so sehr. Der Hauptstreitpunkt war unsere Verwendung des Begriffs "kontinuierliche Lieferung" in einer manuellen Release-Umgebung. Wenn Sie Teil eines Teams sind, das täglich Hunderte von Releases bereitstellt, funktioniert unsere Struktur möglicherweise nicht für Sie. Wenn Sie jedoch wie wir in einer stark regulierten Branche wie dem Finanzwesen arbeiten, in der Releases besser kontrollierbar sind und Sie die Funktionen für Verzweigung, automatische Integration, automatisches Hosting und Versionierung optimal nutzen möchten, funktioniert diese Lösung möglicherweise auch für Sie. wie für uns



, «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 ist Absolvent des Stevens Institute of Technology, wo er seinen Bachelor- und Master-Abschluss in Informatik erworben hat. Brian arbeitet derzeit bei Nomura als Software Engineer in der Infrastructure Development Group. Er verbringt seinen Tag hauptsächlich mit der Arbeit an Spring Boot-Back-End-Diensten oder Big Data-Pipelines mit Apache Spark.




All Articles