[Demo Webinar] How to Orchestrate IaC Workflows with Spacelift

➡️ Register Now

General

CI/CD Best Practices – Top 11 Tips for Successful Pipelines

ci cd best practices

🚀 Level Up Your Infrastructure Skills

You focus on building. We’ll keep you updated. Get curated infrastructure insights that help you make smarter decisions.

Continuous integration and continuous delivery are central concepts in modern cloud application development and beyond.

The core of this concept is to integrate code changes into a shared code base and automate the delivery of these changes to the end-users. The exact steps involved in this process are different for every context and environment, but the overall goal is the same: automate the deployment process.

In this blog post, we will learn about continuous integration and continuous delivery, focusing on CI/CD best practices.

What is CI/CD?

Continuous integration and continuous delivery (CI/CD) is a set of practices for transforming a change from inception to production. This includes testing, building, packaging, delivering, and possibly deploying and releasing the change.

The main vehicle for this process is the CI/CD pipeline. In essence, a CI/CD pipeline consists of a number of steps that are executed in sequence or in parallel. Each step takes the change one step closer to being available for your end users.  The CI/CD process is often performed by a dedicated platform or by several different systems and tools working together. 

Think of a CI/CD pipeline as a production line in a car factory, where a car moving through the production line progresses from initial separate parts to a finished car that can be sold to a customer.

The CI, continuous integration, part of CI/CD refers to the process of integrating a change with an existing code base and with other changes coming in simultaneously. Today, this is mostly done through the use of a version control system (VCS), where many developers can collaborate and commit new code. Changes are tested together in an automated fashion to ensure that the code base stays in a healthy state and that all changes are compatible with each other.

The CD part of CI/CD is commonly called continuous delivery, but it can also refer to continuous deployment. The distinction between delivery and deployment is important:

  • Continuous delivery prepares a deployment artifact for production but does not actually implement the change. An example of this could be building and testing an application and packaging it into a Docker container that can be used in the next deployment. The end result is an artifact (e.g., a Docker image) ready to be released.
  • Continuous deployment takes it one step further and also automates the last part of making the artifact run in the production environment. This can include automated blue/green deployment or another advanced deployment strategy.
    Continuing the Docker image example, automating its deployment might involve referencing the Docker image in a Kubernetes pod manifest and creating pod instances running in your cluster. If any issues are detected with the newly released version, there is an automatic rollback to the old version.

What makes a good CI/CD pipeline?

A good CI/CD pipeline is fast, reliable, automated, and easy to maintain. It includes code testing, builds, deployments, and rollback mechanisms. It ensures quick feedback, integrates seamlessly with version control, and supports parallelism and scalability.

10+ CI/CD best practices to streamline DevOps workflows

There are several best practices for CI/CD to consider. Some overlap with best practices for your overall cloud and development environments, but they can be even more important in the CI/CD context.

CI/CD best practices include:

  1. Start small and scale up slowly
  2. Have a version control system
  3. Use infrastructure as code 
  4. Automate
  5. Fail fast and fix fast
  6. Pick the right tools
  7. Shift security and governance left
  8. Monitor your CI/CD environment
  9. Secure your CI/CD environment
  10. Enable rollbacks in case of failure
  11. Test everything

1. Start small and scale up slowly

CI/CD platforms and tools offer many capabilities. When starting out, implementing a new platform or tool, it can appear as an overwhelming task. As with other complex systems, it is best practice to start small and scale up slowly.

If you are introducing a new CI/CD system in your organization, a good option is to initially onboard a single team. This team will act as ambassadors of the new system. Make sure that the system works well for this team and that any issues are addressed before you onboard new teams.

If you are onboarding a new platform for cloud infrastructure management (e.g., Spacelift), a good idea is to start with a single well-defined part of your infrastructure to make sure all related processes and operations work as intended before you scale up to manage all your infrastructure via the platform.

2. Have a version control system

You can do CI/CD without using a VCS for your source code. However, this is generally a bad idea that involves a lot of manual work or manual tooling.

Some CI/CD platforms include a VCS component (e.g., GitHub, GitLab, and Azure DevOps) or they integrate with popular VCS systems. Make sure that the platform you are planning to onboard for your organization integrates with your VCS system. If not, this would be a reason to reevaluate the choice of CI/CD platform.

Above all, VCS enables a level of collaboration between developers that is hard to achieve using other means.

3. Use infrastructure as code

Infrastructure as code (IaC) is the foundation for automating your cloud infrastructure deployments. In addition to declaring your cloud infrastructure as code, you could also declare your CI/CD environment in code.

This practice will give you the same benefits for your CI/CD environment as for the rest of your cloud infrastructure. One important aspect is disaster recovery. Being able to bring back a working CI/CD environment for your applications and cloud infrastructure in case of a disaster is equally important as getting the rest of your cloud infrastructure back.

If you use an IaC tool that supports multiple providers (e.g., Terraform, OpenTofu, or Pulumi), you can build templates that set up a team’s CI/CD environment. These templates can include VCS repositories, cloud provider credentials, CI/CD pipelines, and more.

4. Automate

The CI/CD platform is often central to your automation environment. Use it to automate as much as possible in the lifecycle of a code change, from inception to production.

The concretization of automation is the CI/CD pipeline. A pipeline is a series of tasks that are performed one after the other, or sometimes in parallel. Typical steps in the CI/CD pipeline are test, build, and deploy. 

In general, the trigger for a CI/CD pipeline is the commit of a code change to a VCS system. Most code changes should go through a test and build phase. However, not all changes should move to the delivery or deployment phase.

5. Fail fast and fix fast

A good CI/CD pipeline should discover errors early. How early this is depends on the type of error.

Syntax errors, missing dependencies, and failing unit tests are examples of errors that should be detected early. You do not want a CI/CD pipeline to progress through 10 minutes of different testing and building stages just to discover that a typo in your source code is failing the code build. Some of these errors should preferably be captured before code is committed to a VCS, but this might not always be possible.

It will be difficult to discover errors early in integration and end-to-end testing, but the point is to catch errors as early as possible.

The general idea is to fail fast. Trivial errors that can be detected early should be detected early. This allows you to focus on fixing the errors quickly before switching context to a different task while you wait for the pipeline to progress.

6. Pick the right tools

There is a vast selection of CI/CD tools and systems available. Most CI/CD tools focus on testing, building, and deploying code. However, there are tools that focus on related areas, such as project planning and issue tracking.

CI/CD tools, systems, and platforms could be divided into a few different categories:

  • Dedicated platform: Platforms provide a suite of integrated tools for CI/CD. A good example is GitHub. GitHub has primarily been used for its VCS features, but the platform also offers tools for project management, issue tracking, package management, and automation. The part of GitHub most commonly associated with CI/CD is GitHub Actions.
  • Specialized platform: There are platforms that focus specifically on one or a few different areas of CI/CD. Examples include issue tracking and project management platforms (e.g., Jira), cloud infrastructure provisioning and management platforms (e.g., Spacelift), and more.
  • Provider-native tools: If you are using a big cloud provider, you can choose to use the cloud provider’s native tools for CI/CD. One example is AWS CodeSuite, which includes AWS CodePipeline, AWS CodeBuild, and AWS CodeDeploy.
  • Technical tools: Some tools provide the building blocks to construct your own CI/CD systems. An example is Tekton, a cloud-native CI/CD system. With Tekton, you define your tasks and pipelines using Kubernetes manifests and run them natively in your Kubernetes clusters. A different example is Dagger, which allows you to build pipelines using different programming languages.

As with other tool and platform selections, you should evaluate which are the best fit for your context and environment. It is not uncommon to use a mix of different tools and platforms to create the right CI/CD environment for your organization.

When you shift to treating infrastructure like a software project, you need all of the same components that a software project would have. That means having a CI/CD platform in place, and most aren’t suited to the demands of IaC. Insurtech company Kin discovered that Spacelift was purpose-built to fill that gap.

Spacelift customer case study

Read the full story

7. Shift security and governance left

Security and governance should be part of your CI/CD pipeline.

Depending on the types of changes the pipeline handles, your pipeline can include a number of security-related tasks. Examples include scanning application dependencies, performing penetration testing of a running web application, and scanning code for unintentional secret values.

Related to application and infrastructure security is the concept of governance. Governance is often imposed at a higher level than for individual teams. 

Policy as code is a concept for declaratively applying policies for governance at scale for cloud infrastructure and applications. Policies are often used to ensure your cloud environment meets requirements from different compliance frameworks, such as the PCI DSS compliance framework for organizations handling credit card data.

policy as code

You can also set up policies to ensure that security standards are followed, e.g., that no Amazon S3 bucket is publicly available.

Specifically for your CI/CD platform, you could write policies that require any CI/CD pipeline to include vulnerability scanning and ensure that certain organization templates are used instead of custom templates for infrastructure deployment tasks.

8. Monitor your CI/CD environment

Monitoring your CI/CD environment is almost as important as monitoring your applications. The goal of monitoring your CI/CD environment is to streamline the delivery of value to your end-users.

There are two main views you can take on monitoring for your CI/CD environment:

  • Monitoring for failures: Treat your CI/CD systems as an application where you and your team are the end users. When a failure occurs, you should team up to investigate and solve the issue swiftly. 
  • Monitoring for efficiency: Identify areas for improvement by measuring the time spent in different stages of your CI/CD environment. For example, you could identify issues such as a specific test suite suddenly taking much longer than before.

The teams using the CI/CD system should primarily consume both types of monitoring. However, the platform team responsible for the CI/CD environment will also benefit from this monitoring.

Improper monitoring of your CI/CD environment leads to increased lead times for changes to move to production and could cause changes to queue up and affect the whole development team or even other teams.

9. Secure your CI/CD environment

Security should be a priority for your CI/CD platform, as it is often an entry point to the rest of your cloud environments.

Keep the following in mind when it comes to securing your CI/CD environment:

  • Use a secure authentication method to access the CI/CD environment. Preferably, the CI/CD system should support the main authentication method you use in your organization (e.g., Microsoft Entra ID or Okta). Require strong passwords and enforce multi-factor authentication (MFA).
  • Limit the number of users who are assigned administrator permissions on the CI/CD platform. 
  • Use a least-privilege mindset and restrict user access to only what they need to perform their job.
  • Assign permissions based on groups of users instead of individual users. This simplifies permissions management and limits forgotten permissions assigned to individual users.
  • Ensure that any external system that your CI/CD environment is secured to the same standards. This includes external artifact stores, cloud provider environments and version control systems. Your security posture is only as strong as the weakest link.

Read more: 20 CI/CD Security Best Practices 

Aside from the best practices mentioned above, keep security in mind when picking your CI/CD platform. For example, security is one of Spacelift’s biggest priorities, and apart from the state-of-the-art security solutions that are embedded inside the product like Policy as Code, Encryption, Single Sign On (SSO), Private Worker Pools, and others. 

In some organizations, engineers are accustomed to certain tools and want to integrate them. When it comes to integrating security tools in your workflows, Spacelift has you covered with the Custom Inputs feature. Read more on integrating security tools with Spacelift.

Spacelift also adds an extra layer of policy that allows you to control – separately from your infrastructure project – what changes can be made, when, and by whom. This isn’t only useful to protect yourself from the baddies but allows you to implement an automated code review pipeline. Check out the documentation.

10. Enable rollbacks in case of failure

Moving from continuous delivery to continuous deployment often requires changes to your CI/CD system. Continuous deployment also requires implementing robust deployment strategies, including automating rollbacks in case of failure.

One example of a deployment strategy with rollback is blue/green deployment. In the blue/green deployment model, you deploy a new version (green) of your application to new infrastructure components (e.g., virtual machines or Kubernetes pods). 

You switch the traffic from your application’s old version (blue) to the new version while monitoring its behavior. If the metrics indicate an issue in the new version (e.g., your application is responding with HTTP 500 errors), this should automatically trigger a rollback to the old version.

The benefit of using a deployment strategy with automatic rollback is that you can deploy changes more often with confidence that any issues will have a minimal impact on your users.

11. Test everything

Your CI/CD pipeline should include automated tests. Whenever you identify a failure in your application or infrastructure, you can include a test to ensure it does not happen again without your knowledge.

Automated testing starts with unit testing for your applications. This should be the bulk of your tests. The next step is to introduce integration testing between different components of your application and its dependencies.

Depending on what type of application you are building, other types of testing could be of interest. Things to consider include security testing (penetration testing, dependency scanning, code vulnerability scanning, and more), load testing, and contract testing.

Testing is not just for end-user applications. You should also build automated tests for your infrastructure (e.g., using the test framework for Terraform, OpenTofu, or similar frameworks). You can even write tests for your CI/CD systems.

To get the most out of your automated tests, it’s important to run them in reliable, isolated test environments that closely match your production setup. This includes everything from infrastructure and configurations to data models. By using infrastructure-as-code, you can create test environments on demand during your pipeline runs. 

Some tests are not suitable for automation. These include manual exploratory testing and user-acceptance testing, which, by definition, should be performed manually by end-users.

How can Spacelift help you improve your CI/CD pipelines?

A successful DevOps implementation requires capable tools that automate your processes, including CI/CD, IaC, and infrastructure management. These fields can be tricky to get right, but dedicated platforms make it easy to control your infrastructure resources, saving valuable time that can be returned to your business.

Spacelift is an IaC management platform that helps you implement DevOps best practices. Spacelift provides a dependable CI/CD layer for infrastructure tools, including OpenTofu, Terraform, Pulumi, Kubernetes, Ansible, and more, letting you automate your IaC delivery workflows.

Spacelift is designed for your whole team. Everyone works in the same space, supported by robust policies that enforce access controls, security guardrails, and compliance standards. You can manage your DevOps infrastructure much more efficiently, without compromising on safety.

what is spacelift

With Spacelift, you get:

  • Policies to control what kind of resources engineers can create, what parameters they can have, how many approvals you need for a run, what kind of task you execute, what happens when a pull request is open, and where to send your notifications
  • Stack dependencies to build multi-infrastructure automation workflows with dependencies, having the ability to build a workflow that, for example, generates your EC2 instances using Terraform and combines it with Ansible to configure them
  • Self-service infrastructure via Blueprints, or Spacelift’s Kubernetes operator, enabling your developers to do what matters – developing application code while not sacrificing control
  • Creature comforts such as contexts (reusable containers for your environment variables, files, and hooks), and the ability to run arbitrary code
  • Drift detection and optional remediation

If you want to learn more about what you can do with Spacelift, check out this article.

Do you plan to implement DevOps in your organization? Or maybe you are seeking ways to improve your processes? Book a demo with our engineering team to discuss your options in more detail.

Key points

Continuous integration and delivery is key to modern cloud development and software delivery.

Here are some essential CI/CD best practices:

  • Start small—onboard one team, validate the process, then scale.
  • Use version control and infrastructure as code (IaC) for everything.
  • Automate repeatable tasks and fail pipelines fast to fix issues early.
  • Shift security left and monitor systems to catch problems quickly.
  • Secure your CI/CD environment and use safe deployment strategies with rollbacks.

Follow these steps to adopt CI/CD successfully in your organization.

Solve your infrastructure challenges

Spacelift is an alternative to using homegrown solutions on top of a generic CI. It helps overcome common state management issues and adds several must-have capabilities for infrastructure management.

Learn more

Thu, May 15, 2025 @ 11:00am EDT

The First Community-Driven
IaC Conference

Register now