Continuous integration and continuous delivery with git-flow
We have been doing continuous integration and continuous delivery since a while with Subversion commits as the pipelines triggers. Recently, we started using git in some projects with git-flow and we are trying to decide which of the branches of git-flow should we use to trigger the continuous integration and continous delivery pipelines.
Here are two approaches:
- git-flow on more that one master
- Workflow for delivering code to a client using two git repositories (internal and external)
- CI: One git repository fits it all? Or: gitflow for multiple projects
- Git-flow, Which are local v remote branches?
- Git-flow and master with multiple parallel release-branches
- Create a bugfix release when master is several versions ahead
1. Use develop branch
Problem: With git-flow we are supposed to deploy the release (or master) branch in production, so we would have to build two different pipelines, one for continuous integration (branch develop) and one for continuous delivery (branch master). This could introduce bugs in production because the version in production will not be the same that the one in other environments (integration, test, staging).
2. Use master branch:
Problem: This way, we would not have a truly continuous integration, since changes to these branches are pushed not very frequently.
Which is the rigth branch to use in the pipelines?
3 Solutions collect form web for “Continuous integration and continuous delivery with git-flow”
The truth lies between the two. If you want to adopt git-flow in a strict CD pipeline, you should use the release-branch for your CI:
- For every (batch of) develop-branch commit(s), let your CI server automatically create a release-branch and run all your tests on it.
- If it fails, let it report and/or delete the branch, otherwise merge it to master.
The basic idea comes from John Ferguson Smart’s slide about CI/CD in Java Maven projects (BDD in Action, Jenkins Definite Guide).
Git-flow and continous integration are, by definition, incompatible. Branches are a mechanism for delaying integration: when you commit to a branch other than master (or trunk, if you come from Subversion), you are avoiding continous integration. Doing continous integration is simple, but not easy.
In my view, if you want to apply git-flow in Continuous Delivery, you should have two different pipelines as you said in your first approach.
I’d suggest this approach:
1. Develop branch
- Develop branch will trigger the Commit Build: As soon a feature is added to the develop branch (on merge or pull request), the CI will build, test (Unit Testing & Code revision) and package the solution (with a “-develop-vX” suffix). So the team is able to react fast in case of failure.
- Once the Commit Build has finished successfully, the task is done (otherwise, the change is reverted and the developer who committed the change must fix it immediately). In parallel, the Acceptance Test Stage starts deploying the previous build to the Development environment for executing the Acceptance Test Suits (e.g. Functional & Regression testing) without blocking the developer’s work. Once it’s finished, the develop branch status is communicated to the team. Therefore, the team is aware of the solution’s stability during the current Sprint: if the Acceptance Test Stage finishes successfully, the product is ready for merging with the Master branch (Otherwise, it’ll be fixed).
2. Master branch
- Once the Sprint is finished, the stable Developer branch (it’s stable) is merged and tagged to Master Branch. So the Master Branch will trigger the Trunk Commit Build that will build the solution, test it and package for deployment (the package now is stored with a release candidate or master suffix).
- If the Trunk Commit Build finishes successfully (it should work), the Acceptance Test Stage will deploy and validate the acceptance tests against an Integration environment. And in case of success, the new version is ready for production. Otherwise, in case of error at Commit Build or Acceptance Test Stage, the merge is reverted.