before we show how we can apply continuous delivery and deployment using Jenkins pipeline as a code , we need to refresh our mind about the difference between continuous integration vs delivery vs deployment as being show below :
What about releasing process and versioning in continuous delivery :
basically i am not big fan of maven release plugin for some reasons :
Let’s consider the principles of Continuous Delivery.
- “Every build is a potential release”
- “Team need to eliminate manual bottlenecks”
- “Team need to automate wherever possible”
Current drawbacks and limitations of maven release way :
- Overhead. The maven-release plugin runs 3 (!) full build and test cycles, manipulates the POM 2 times and creates 3 Git revisions.
- Not isolated. The plugin can easily get in a mess when someone else commits changes during the release build.
- Not atomic. If something went wrong in the last step (e.g. during the artifact upload), we are facing an invalid state. We have to clean up the created Git tag, Git revisions and fix the wrong version in the pom manually.
So let us simplify the versioning process in an efficient way within out continuous delivery model :
- checking out the software as it is
- building, testing and packaging it
- giving it a version so it can be uniquely identified and tractable (release step)
- deploying it to an artifact repository where it can then be picked for actual roll out on target machines
- tagging this state in SCM so it can be associated with the matching artifact
Which leads to :
- Every artifact is potentially shippable. So there is no need for a dedicated release workflow anymore!
- The delivery pipeline is significantly simplified and automated
- Traceable. It’s obvious, which commits are included.
So how we can implement continuous delivery and a conditional continuous deployment using Jenkins pipeline , off-course you can add more stages based into team process like for example performance test, just added till acceptance as production will be just the same :
we will use Jenkins pipeline as a code as it give more power to the team to control they delivery process:
- when a Git commit is triggered to development branch , it will trigger Jenkins pipeline to checkout the code , build it , unit test it and if all is green it will trigger the integration test plus sonar check for your code quality gate
- if all green , deploy to development server using the created package from Jenkins work space or Nexus Snapshots if you prefer
- then if there is a release candidate which means a merge request to your master branch , the it will do the same steps as above plus creating the release candidate using the release versioning explained above.
- Push the released artifact to Nexus and do acceptance deployment and auto acceptance functional testing
- Then prompt to production and if it is approved it will be deployed into production
- Off-course deployment task must be automated if you need continuous deployment using an automation tools like Ansible or other options.
Now let us explain how it will be done via Jenkins Pipeline code as the following :
then you can use it by creating multi branch project in Jenkins and mark it to get use Jenkins pipeline as a code