Blog CI/CD best practices: 4 tips for DevOps teams 5 min
DevOps

CI/CD best practices: 4 tips for DevOps teams

SparkFabrik Team5 min read
CI/CD best practices: 4 tips for DevOps teams

Continuous Integration (CI) and Continuous Delivery (CD), or CI/CD for short, are now an integral part of a development approach aimed at reducing errors during integration and the subsequent delivery of new features. These two practices greatly simplify the development and release cycle, making it more robust and resilient while considerably increasing application quality.

YOU MIGHT ALSO BE INTERESTED IN: How to introduce DevOps in your organisation

In this article, we analyse some of the best practices you should follow to get the most out of pipelines built for CI/CD.

Measure the effectiveness of your agile process in qualitative and quantitative terms

Any repeatable process must be measurable: doing continuous integration and delivery means repeating the build, test and release processes dozens, if not hundreds of times a day. How do you monitor the performance of these pipelines?

In an Enterprise context that embraces an Agile development methodology such as Scrum or Kanban, tools like Gitlab and Jira 1 can be used throughout the entire application lifecycle to plan, track and monitor the development of new features and the release of bugfixes. At the same time, they offer dashboards, kanban boards, scores and milestones to provide useful metrics for evaluating the project’s status at any given moment.

Finally, the direct integration that some of these tools support (User Story -> Pull Request) with the branching strategy (such as Gitflow 2) adopted by your development team is extremely valuable.

Promote testing as a development mindset, not just in automation

The best way to do effective testing is to divide the process into multiple phases: unit testing scripts should be set up from the very beginning and run during development and as git hooks using tools like Pre-commit 3 or typicode/husky. There are dedicated libraries for every language, such as Jest 4, the Golang testing module 5, PHPUnit or PyTest/PyMock 6.

During the run phase of a CI/CD pipeline, it is useful to run the entire test suite, including unit tests, functional tests and end-to-end tests, using tools like Selenium or Cypress 7. With this in mind, it is useful to set up data mocking or at least have fixture/seed scripts and infrastructures that are as immutable as possible (IaaC), ready to be created on-demand, used for testing, and then destroyed to reduce maintenance costs.

It is also important to introduce visual regression testing tools, which allow you to verify that cross-platform interfaces are not affected by visual regressions, using tools like BackstopJS or Percy 8.

In contexts where release reliability is mission-critical and no regression is acceptable, it can be highly effective to complement test automation scripts with the adoption of a development technique such as TDD (Test Driven Development) 9.

A repeating process, like a CI/CD pipeline, must be fast

To speed up a CI/CD pipeline, you can rely on on-demand solutions capable of handling a greater number of requests as workload increases: Gitlab, Github Actions, Travis CI, CircleCI 10 are all valid alternatives. There are also serverless or hybrid solutions where part of old on-premise hardware can be repurposed as a workforce to manage build and testing processes, even orchestrated by cloud-based solutions like those mentioned above. There are caching techniques managed by various package managers (Composer, Yarn, npm 11) and best practices for building Docker containers that maximise the reusability of previous steps, without unnecessarily repeating build stages.

ALSO READ: What is GitOps and when should you adopt its practices?

Promote small, tested releases to reduce the risk of errors

Many of the tools supported by the most prominent vendors on the market and maintained by the most active communities, such as Docker, Terraform, Hugo, Node and others, are released following the principle of Semantic Versioning 12, sometimes almost daily. The best way to adopt the same approach is to equip yourself with cutting-edge deployment techniques, such as canary deployment, which allows you to release a package to a targeted user group during an exploratory phase, and only later promote a rolling update to everyone.

At the same time, it is wise to promote a development technique that embraces the concepts of immutability, DRY and KiSS principle, also during the release phase: that is, frequent builds that are easily reproducible, without repetitions (both at code level and in terms of artefact production), and with as few features per release as possible.

In contexts where the release is mission-critical and/or it is not possible to isolate a user group for preliminary testing, it is advisable to use more robust (and costly) release techniques, such as Blue Green deployment.

Conclusions

One of the greatest challenges, like most challenges in the world of Cloud Native development and DevOps, is the change of mindset in code production.

Following these basic principles can help you effectively implement CI/CD pipelines and strengthen the testing and development phase of a product or service, while embracing sound and opinionated principles.

References**

1: Jira is a software development tool used by agile teams worldwide. Gitlab is another valid platform for keeping the team organised and connected.

2: Gitflow Workflow is a branching strategy model that revolves around project releases: more information here.

3: Pre-commit is a framework for managing and maintaining multi-language pre-commit hooks.

4: Jest is a JavaScript testing framework that works with Babel, TypeScript, Node, React, Angular, Vue and many others.

5: The Golang testing module provides support for automated testing of Golang packages.

6: The PyMock framework is for developers who want to implement unit testing in Python. The PyTest framework simplifies writing small tests, but scales to support complex functional testing for Python applications and libraries.

7: Selenium is one of the most widely used browser automation tools, primarily used for automated web testing. Cypress is a tool that makes testing faster, simpler and more reliable.

8: BackstopJS is a visual regression testing tool for web apps. Percy is a visual review platform that allows you to automate visual testing.

9: Test-driven development is attributed to Kent Beck, one of the fathers of extreme programming (XP) and agile methodologies.

10: There are many providers with various free plans integrated with different versioning platforms: among them we mention Gitlab, Github Actions, Travis CI and CircleCI. At the end of 2019, Github released Github Actions to the public, which integrate directly with Github and allow the use of external build nodes in addition to cloud ones.

11: Some package managers like Yarn and NPM provide built-in caching systems: Codefresh discusses this, and positions itself as a valid alternative, here.

12: Semantic versioning consists of a simple and effective set of rules and requirements that determine how release numbers are assigned and incremented.

Get in touch

Follow us on social media
Listen to Continuous Delivery