Trigger Pipelines using Git Event Payload Conditions

Updated 1 month ago by Manish Jaiswal

You can trigger Pipelines in response to Git events that match specific payload conditions you set up in the Harness Trigger.

For example, when a pull request or push event occurs on a Git repo and your Trigger settings match the payload conditions, a CI or CD Pipeline can execute.

In this example, we create a Custom Trigger for GitHub payload conditions.

This topic covers payload conditions in detail. For a general overview of creating Triggers using Git Events, see Trigger Pipelines using Git Events.

For general Triggers reference, see Triggers Reference.

In this topic:

Before You Begin


  • Currently, Harness supports Git-based Triggers for the most common Git providers. Harness includes a Custom Trigger for other repo providers.

Step 1: Add a Trigger to a Pipeline

  1. Open your Harness Pipeline in Pipeline Studio.
  2. Click Triggers.
  3. Click New Trigger.
  4. Click Custom

Step 2: Set up Webhook Listener

Enter a name for the Trigger.

In Payload Type, Custom is selected automatically. 

Click Continue.

For details on the payloads of the different repo Webhooks, see GitHub Event Types & Payloads, Bitbucket Event Payloads, and Gitlab Events.

Step 3: Set Trigger Conditions

Conditions specify criteria in addition to events and actions.

Conditions help to form the overall set of criteria to trigger a Pipeline based on changes in a given source.

Conditions support Harness built-in expressions for accessing Trigger settings, Git payload data and headers.

Option 1: Header Condition

In the Header condition, enter the Git Webhook Header data that matches your value. 

The header expression format is <+trigger.header['key-name']>

For example: <+trigger.header['X-GitHub-Event']>.

Refer to Built-in Git Trigger and Payload Expressions for more trigger expressions in Harness.

Option 2: Payload Condition

Conditions based on the values of the JSON payload. Harness treats the JSON payload as a data model and parses the payload and listens for events on a JSON payload key.

To reference payload values, you use <+eventPayload. followed by the path to the key name.

For example: <+eventPayload.repository.full_name>

For details on Payload Condition, see Payload Condition.

Option 3: JEXL Condition

JEXL expressions are also supported. For example: <> == "repositoryOwnerName"

For details on Trigger settings, see Triggers Reference.

If you select all three conditions, the conditions are ANDed together (boolean AND operation). All Conditions must match an event payload for it to execute the Trigger. If you select any one condition, Trigger will execute based on the condition you entered.

Click Continue.

Step 4: Set Pipeline Input

Pipelines often have Runtime Inputs like codebase branch names or artifact versions and tags.

Provide values for the inputs. You can also use Input Sets.

Click Create Trigger.

The Trigger is now added to the Triggers page.

Step 5: Register Webhook 

When you create or edit the custom webhook trigger, you need to copy the webook URL and add it to your repo webhooks. However, make sure you have the following permissions for GitHub Personal Access Token for webhook registration to work:

  • Scopes: select all the repo, user, and admin:repo_hook options

You should also be repo admin.

  1. In the Pipeline Studio, click Triggers.
  2. Select your Custom Webhook.
  3. Click on Webhook URL icon.
  4. Select Copy as Webhook URL.
  1. Log into your repo in the Git provider and navigate to its Webhook settings. 
  2. Click Settings, Webhooks, Add webhook.
  3. Under Payload URL, paste the webhook URL you copied from Harness in Step 4.
    The format for the custom Webhook is:

    The pipelineIdentifier and triggerIdentifier target the Webhook at the specific Pipeline and Trigger.

    Is some cases, you will not want to target the Webhook at the specific Pipeline and Trigger. For example, there are events in GitHub that are not covered by Harness and you might want to set up a Trigger for those events that applies to all Pipelines and their Triggers in the Project.
    To instruct Harness to evaluate the custom Trigger against all Pipelines (until it finds a Conditions match), remove pipelineIdentifier and triggerIdentifier from the URL before adding it to your repo.
    The orgIdentifier and projectIdentifier are mandatory.
  4. In Content type, select Application/json.
  5. In SSL verification, select Enable verification.
  6. Select events that you would like to trigger this webhook.
    In this example, we select Just the push event. It means that this webhook will only be triggered if there is any push event.
  7. Click Update webhook.

Step 6: Test Trigger

Make a change on the repo and push the changes to Github and see if it executes the Trigger. For example, change a file, commit it on the main branch, and make a push event.

In your Git provider repo, you can see that the request and response were successful.

Note that the webhook conditions specified in Step 3 match the Payload data. As a result, the Pipeline was triggered.

In Harness, view the Pipeline execution.

In Harness CI, click Builds.

You can see the source and target branches. You can also see the push request comment and number.

Click the push request number and it opens the Git provider repo at the push request.

If you open the Trigger in the Pipeline, you will see a status in Last Activation Details.

Activation indicates that the Trigger was successful in requesting Pipeline execution.

See Also

Please Provide Feedback