Blog
Harness Platform

How to Automate CI/CD Pipeline Execution with Event-Driven Triggers | Harness Blog

Learn how triggers automate CI/CD pipelines and explore the various trigger types available for complete automation.

TL;DR

  • CI/CD pipeline automation uses triggers to automatically execute builds, tests, and deployments based on events like code commits, artifact updates, or schedules.
  • Git event triggers respond to webhooks from repositories, allowing pipelines to run whenever code is pushed to specific branches or pull requests are opened.
  • Artifact triggers monitor registries like Docker Hub or Artifactory and start deployment pipelines when new images or packages are published.
  • Scheduled triggers use cron syntax to run pipelines at regular intervals for tasks like nightly builds, compliance scans, or automated backups.

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

Automated CI/CD pipeline flow from developer commit to production, showing build, test, and deploy triggers

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. 

Continuous Integration/Continuous Delivery (CI/CD) 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
  • 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.

Harness Pipeline Studio menu highlighting the Triggers tab next to Input Sets and Execution History

Start configuring your trigger.

The Triggers tab in the Harness pipeline studio with an Add New Trigger button

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

Webhook trigger options in Harness with GitHub selected among GitLab, Bitbucket, Azure Repos, and Custom

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

Webhook trigger configuration in Harness with GitHub payload type, push event, and repository URL

You can also add conditions for more specific trigger events. 

Configuring optional conditions like Branch Name and Changed Files for a webhook trigger in the Harness UI

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

Harness UI showing the "On New Webhook" trigger configuration with the Pipeline Input step set to "No Runtime Inputs"

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

Harness Triggers tab displaying the newly created Sample Trigger under the Guestbook App Deployment pipeline

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. 

Successful Guestbook App Deployment pipeline execution triggered by a webhook in the Harness UI

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

Selecting webhook events like Pull Request, Push, or Release in the Harness trigger configuration UI

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. 

Artifact trigger options in Harness with Docker Registry selected as the event source

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

Configuring a Docker Registry Trigger in Harness to listen on a specific artifact repository location

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.

Conditions tab of an On New Artifact trigger in Harness, showing the Artifact Build operator dropdown menu

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

Pipeline Input configuration step for the On New Artifact trigger showing No Runtime Inputs

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.‍

Docker Registry Trigger in the Harness UI showing a successful activation 45 seconds ago

Click on pipelines to see the execution details.

Successful execution of Guestbook App Deployment pipeline triggered by Docker_Registry_Trigger in Harness

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.

Cron trigger option under the Scheduled category in the Harness pipeline trigger setup
Harness pipeline schedule configuration screen showing an hourly trigger set to run every hour using cron

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.

More About Automating CI/CD Pipelines

Cloud-Based CI/CD Workflows
Automated Security Testing in CI/CD Pipelines
How to Migrate Off Jenkins: Guide
← Previous:
Next: →

FAQs

Related Resources

CI/CD for Serverless

Continuous Delivery & GitOps

CI/CD for Serverless

January 19, 2024

Dewan Ahmed

+ more
7 minutes to read

Get Started

Get Started with Harness AI

Try the full platform free. No module restrictions, no credit card.

Pavan Belagatti
Developer Advocate
Pavan is an award winning developer evangelist.
pavan-belagatti
Pavan Belagatti