No items found.
Product
|
Cloud costs
|
released
August 11, 2023
|
3
min read
|

Automate Your CI/CD Pipeline Using Triggers

Updated

Continuous integration (CI) and continuous delivery (CD) are the two important aspects of a DevOps pipeline. While CI helps you with building and testing, CD helps you deploy your applications and services to the target environment. A great DevOps approach always starts with having the best set of tools to perform CI and CD and some best practices. The aim of DevOps is automation and accelerating the time to market. In this sense, CI/CD is a superpower to help organizations speed and automate. A CI/CD pipeline should always be configured in an automated fashion so that whenever a developer merges his/her code to the repository's main branch, the CI/CD system should get triggered. 

In this article, let us learn how to set up CI/CD pipelines in an automated fashion using triggers. 

CI/CD Pipeline Automation

Today, organizations like to move fast and break things early. Developers have become even more smarter with the DevOps concepts of CI/CD, GitOps, IaC, etc. As you march towards the DevOps approach, you will understand that automation becomes part and parcel of this journey. Having a great CI/CD platform/tool like Harness is necessary. 

CI/CD (Continuous Integration/Continuous Delivery) pipeline automation is pivotal to modern software development and deployment. It refers to automating the steps involved in building, testing, and deploying software applications. The CI/CD pipeline enables development teams to streamline their workflows, improve collaboration, and accelerate the delivery of high-quality software. By automating the integration and delivery processes, developers can quickly identify and fix bugs, ensure compatibility across various environments, and continuously deliver new features and updates to end users. 

The pipeline typically consists of multiple stages, including code compilation, unit testing, integration testing, and deployment to production. Automation tools and frameworks facilitate the seamless flow of code changes through these stages, allowing for rapid iteration and feedback cycles. With CI/CD pipeline automation, organizations can achieve faster time-to-market, higher software reliability, and enhanced overall efficiency in their software development lifecycles.

CI/CD Pipeline Automation Steps

  • Developer Pushes Code to SCM (Source Control Management) Tool

  • CI Build Gets Triggered

  • Build Process

  • Artifact Generation

  • Artifact Storage

  • Staging Environment

  • CD Tool Takes Charge

  • Testing in Staging

  • Approval and Promotion

  • Deployment to Production

By automating these steps, CI/CD pipeline automation streamlines the software delivery process, reduces manual errors, and enables teams to rapidly deliver reliable software updates to production. 

If you notice carefully, Triggers serve as the connecting links between these CI/CD steps, automatically initiating actions such as builds, deployments, and tests based on events like code commits, repository changes, or approval signals, enabling seamless automation and integration across the entire CI/CD pipeline.

Let us practically understand how to automate a CI/CD pipeline using triggers. 

Prerequisites

Harness Triggers Tutorial

Triggers in the Harness platform are used to automatically start a pipeline or workflow in response to a specific event. They can be configured to run pipelines in response to a variety of events, such as:

  • Git events: When a change is made to a Git repository, a trigger can be configured to run a pipeline. This can be used to automate the build, test, and deploy process for any application that is hosted in a Git repository.
  • Artifact events: When a new artifact is created or updated, a trigger can be configured to run a pipeline. This can be used to automate the deployment of new features or bug fixes to production.
  • Schedules: A trigger can be configured to run a pipeline on a schedule, such as once a day, once a week, or once a month. This can be used to automate the deployment of new features or bug fixes to production on a regular basis.
  • Manual triggers: A trigger can be triggered manually by a user. This can be useful for troubleshooting or for deploying changes to production outside of the normal schedule.

Git Event Trigger

For example, you could create a trigger that starts a pipeline whenever a new commit is pushed to a specific branch in your Git repository.

Signup at Harness, create a project and create a pipeline in the project. 

Go to your pipeline studio and click on the ‘Triggers’ tab.

Start configuring your trigger.

When you click ‘Add New Trigger’, you will be presented with all the possible options for your trigger. 

Let’s select ‘GitHub’ and continue adding all the required details. 

You can also add conditions for more specific trigger events. 

As we don’t have any runtime inputs, keep it as is. 

Create the trigger and your newly created trigger will appear under the ‘Triggers’ tab. 

Now, let’s push something to the main branch of the application repository. You should see an automated pipeline trigger as soon as the new code push happens to the main application repo. 

Similarly, you can create triggers for different events, as shown in the image below.  

Docker Registry Trigger

Let’s consider one more scenario where you want your pipeline to trigger when a new image or an artifact is pushed to the defined path. Let’s pick ‘Docker Registry’ from the available options below. 

You define the artifact source and add the required details, such as your artifact type, artifact repo connector, location, etc. 

So the location is very important here. Make sure you add it correctly. When any new image or artifact gets pushed to that path, the pipeline gets triggered. 

To make it more specific, you can add conditions as to when you want the trigger to occur. We will keep it blank as of now.

There is no runtime input required, so keep it as is. 

Create the trigger, and you can see the newly created trigger under the ‘Triggers’ tab.

It is time to see if this new trigger is working as expected or not. Let’s push a new image to the path/location specified in the artifact source with a different tag (other than ‘latest’).

We can see the pipeline triggering action as soon as the new image gets pushed.

Click on pipelines to see the execution details.

This way, you can configure any events to trigger the pipeline automatically. 

You can also schedule pipelines using triggers at Harness. Select ' Cron ' in the ‘Triggers’ tab and mention when you want your pipeline to run.

Benefits of Using Triggers

Harness platform provides several benefits when it comes to using triggers. Triggers are essential components of a CI/CD pipeline that help automate the deployment process based on specific events or conditions. Here are some benefits of using Harness triggers:

  1. Automation: Triggers enable automation by initiating the execution of CI/CD pipelines based on predefined events. These events can include code commits, pull requests, specific time intervals, or external system notifications. By automating the pipeline execution, triggers save time and effort for the development and operations teams.
  1. Speed and Reliability: Triggers can automate the CI/CD process, which can help to improve the speed at which new features and bug fixes are deployed to production. Triggers can help to improve the reliability of the CI/CD process by ensuring that pipelines are always run in response to the desired events.
  1. Deployment Orchestration: Triggers enable the automatic deployment of applications to various environments based on specific conditions. For example, you can configure a trigger to initiate the deployment process when a specific branch is merged or when a new version of an external dependency is released. This ensures that your applications are consistently deployed across different environments without manual intervention.
  1. Workflow Flexibility: Triggers offer flexibility in defining workflows. You can configure triggers to execute specific actions based on different events. 
  1. Event-Driven Actions: Triggers in Harness enable event-driven actions, triggering certain activities based on external system events or notifications. 
  1. Enhanced Visibility and Control: Triggers provide visibility into the state of your CI/CD pipeline by tracking trigger events, execution status, and associated actions. This visibility allows you to monitor and control the pipeline effectively. You can view the status of trigger executions, analyze logs, and troubleshoot any issues that may arise during the deployment process.

Overall, using triggers in Harness platform enhances automation, streamlines deployment processes, and improves development efficiency by enabling event-driven workflows and providing visibility and control over the CI/CD pipeline.

Sign up now

Sign up for our free plan, start building and deploying with Harness, take your software delivery to the next level.

Get a demo

Sign up for a free 14 day trial and take your software development to the next level

Documentation

Learn intelligent software delivery at your own pace. Step-by-step tutorials, videos, and reference docs to help you deliver customer happiness.

Case studies

Learn intelligent software delivery at your own pace. Step-by-step tutorials, videos, and reference docs to help you deliver customer happiness.

We want to hear from you

Enjoyed reading this blog post or have questions or feedback?
Share your thoughts by creating a new topic in the Harness community forum.

Sign up for our monthly newsletter

Subscribe to our newsletter to receive the latest Harness content in your inbox every month.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Platform