Setting up Jenkins pipeline seems to be one of the key task achieving ideal way of adopting continuous delivery. While going through this phase, we are going through a lot of new learnings, with the aspect of different team development cycle, technology, platform needs and clients expectation. This place is a great place to document best practices to set up Jenkins jobs.
- Break Job to a granular level: A single Jenkins job to perform multiple tasks is not ideal. Jenkins is a just a build tool and it's not smart enough to know which step has been failed. The essence of creating a pipeline is breaking up a single build process in smaller steps, each having its own responsibility. In this way faster and more specific feedback can be returned.
- The most reliable builds are the one which builds clean and builds fully from Source Code Control.
- All Jenkins builds must follow the packaging principle. Build Once, Deploy Anywhere.
- If you are having own instance of Jenkins, make sure it's secure with user credentials.
- Right usage of plugins is highly expected. There are tons of plugins available for free in Jenkins marketplace. Quite useful plugins are
- Delivery pipeline plugin
- Join plugin
- Parameterized Trigger Plugin
- Clone Workspace SCM Plug-in
- Build Monitor Plugin
If anything goes wrong in critical deployments, first and foremost thing comes in mind and that is Rollback. Considering its importance, still rollback strategy is most undervalued concept in Jenkins jobs and pipeline setup.
- Revision number: Every Jenkins pipeline should use of pipeline revision number across its execution.
- Define a pipeline that is strictly associated with a single revision within a version control system.
- Code base should always go through step of Tag, label, or baseline after the successful build.
- Always Bootstrap Jenkins workspace from scratch to update with working copy prior to running the build goal/target.
- Always configure your job to generate trend reports and automated testing when running a Testing jobs.
- Use of public key authentication: By setting up the public key mechanism, anyone can log in from one system to another system without ever typing password. This is the real timesaver useful for Jenkins.
- Use of Labels: Sometimes it's good to keep more diversity in build cluster. And one of the way to manage the diversity is using labels to a particular node. Right usage of the label helps team in the long run to identify the uniqueness of each node and help them to use it for rightful purpose.
- Parallel execution is a great thing to see the results and feedback quickly. Every pipeline should find out the list of jobs which can be executed in parallel.
- Every job should include relevant script to clean up the operation after completion to maintain cleanliness.
- Jenkins should also include maintenance jobs such as cleanup operations to avoid full-disk problems.
- Always no to Build Record Sprawl. You should discard old build with the configuration option.
- Periodically team should archive unused jobs eventually removing them.
- Almost every pipeline jobs eventually outgrow the ability to run builds on just one machine. Everyone should take Advantage of Distributed Builds. In larger systems, make sure all jobs run on slaves.
- Set up email notifications mapping to developers in the project, so that everyone on the team has his pulse on the project's current status.
- Use of hipchat plugin, logging system is recommended.
- Take steps to ensure failures are reported as soon as possible.