Walkthrough - Quick Implementation of MultiBranch CICD
I had an opportunity to learn about Continuous Integration and Deployment pipelines. I was interested to get this done with less code. Hence, the aim of this walkthrough is to:
- Understand, how CI/ CD Pipeline is implemented at its basic level
- Explore Blue Ocean Plugin for Jenkins (UI available as plugin in Jenkins)
To accomplish the above, the best way is to implement it by myself.
Sample Use Case
In an agile world, software's and their components are continuously integrated, tested and deployed. Developers write code in the form of features which need to be tested. In the end, each completed unit or chunk should be integrated in a big chunk of software aka. Software release. Each developer works on his feature branch which later needs to be reviewed via a Pull request.
Now, the process of reviewing features (code) written by multiple developers and deploying them several times is a time taking process. Automating such processes not only help the developers but also enable companies to bring their software increments quickly in the market.
Below is the high level illustration depicting how feature branches are eventually merged with the release.
To make the process simple, I tried to create a three steps Jenkins pipeline:
Build → Test → Deploy
Build Step - Checkout latest source code from the version control, compile it and generate deployable artifacts
Test Step - Execute JUnit or Integration Testing against the generated artifacts (from Build Step)
Deploy Step - Deploy the same artifact on staging or production environments
Pre-requisites
1. Jenkins
2. Install Jenkins Plugin - Blue ocean (https://plugins.jenkins.io/blueocean/)
3. Branches available in a source code version control - GitHub, Bitbucket, GitLab
Create Jenkins Multi Branch Pipeline
- Go to New Items option
- Enter Multibranch Pipeline name and select option Multibranch Pipeline then Click on OK button
- Below are the configuration of Multibranch Pipeline, enter required configuration such as git repo
Create Jenkinsfile
- Below is the sample jenkinsfile - used by Jenkins
- The file shows three steps Jenkins pipeline: Build → Test → Deploy
Note: For the sake of the example, tests are skipped in the Test stage. Similarly, Deploy stage only prints text on the console.
- Above jenkinsfile should be placed in the repository as shown below
- Commit your changes to the repository- This will trigger the Jenkins recently job
- After completing all implementation and configuration, go to Jenkins → Click on Open Blue Ocean
GitHub Branches
- GitHub branches which we want to use in Jenkins
- The Multi branch pipeline job is My-Automation and all GitHub branches in Jenkins via Blue Ocean are visible.
Pull Request Option
- Through the Pull Requests option, PR and PR Status of branches along-with some additional information such as author name and completed time or day
- Go into branch PR example Develop, the build pipeline flow is opened, and the build pipeline steps can be seen, defined in in jenkinsfile. We have currently three steps:
Build 🡪 Test 🡪 Deploy
At each step, tasks or operations which are executed are visible. For Instance, clicking on the build step will show the build logs. Same goes for the Test and Deploy step.
Conclusion
In my opinion, one can easily implement basic CI and Release pipelines via BlueOcean Plugin without writing too much code.