Skip to main content

Add a pipeline notification strategy

This topic describes how to notify users of different pipeline events using popular notification methods.

You can send pipeline event notifications using email and popular communication and incident management platforms.

Event notifications are set up using Notification Rules in your pipeline. You select the types of events to send, and then select how you want to send notifications. When those events occur, Harness sends event information to those channels and recipients.

This topic describes how to set up Notification Rules in your pipeline.

You can set notifications preferences on user groups also. Go to Manage user groups for more information.

Limitations

Currently, Harness supports several communication and incident management platforms. If you don't see yours, contact Harness.

note

It's important to note most of the Notification Rule settings, including the Slack Webhook URL, cannot be specified using runtime inputs. This information must be provided before the pipeline execution begins. However, you can use expressions to provide this information. Refer to the Input options available in the respective Notification Rule settings for more information.

Requirements

To create or enable a notification rule, a user must belong to a user group with a role that has the pipeline Create/Edit permission.

Add a notification rule

In your pipeline, select Notify.

To create a new notification rule, select Notifications. The Notification Rule settings appear.

Enter a name for the notification rule. You might want to edit the name after you've selected the events that trigger the rule.

Select Next.

Select events

In Pipeline Events, select the events that will trigger the notification.

You can select events for the pipeline or stages.

If you select the stage events, you can select which stages to use.

Select Continue.

There are different communication and incident management platforms to use for the notification rule. Their settings are described below.

The events are self-explanatory, but there are a few considerations:

  • If you select both Pipeline End and Pipeline Success, you'll get two notifications.
  • Pipeline Pause only applies to a manual pause of the pipeline execution. Pending approval steps don't trigger the pipeline pause event.

Email notifications

For email notifications, simply type in the email addresses that you want to notify.

Enter multiple addresses as a comma-separated list. For example, john.doe@example.io,qateam@example.io.

Here's an example of an email notification for the pipeline Start event:

Along with the start date and who triggered the pipeline, the email includes a link to the pipeline execution in Harness.

Slack notifications

For Slack notifications, you simply create a webhook in Slack and paste it into the Slack Webhook URL setting in the notification rule.

Follow the steps in Slack documentation for creating a Slack app, selecting your channel, and creating a webhook: sending messages using incoming webhooks.

When you are done, you'll have a webhook that looks something like this:

Copy the webhook.

You either paste the Webhook into Slack Webhook URL or add it as an encrypted text in Harness and reference it here.

For example, if you have a text secret with the identifier slackwebhookURL, you can reference it like this:​

<+secrets.getValue("slackwebhookURL")>​

You can reference a secret within the Org scope using an expression with org:​

<+secrets.getValue("org.your-secret-Id")>​​

You can reference a secret within the Account scope using an expression with account:​

<+secrets.getValue(“account.your-secret-Id”)>​​​

PagerDuty notifications

For PagerDuty notifications, enter the key for a PagerDuty account or service or add it as an encrypted text in Harness and reference it in PagerDuty Key. Harness will send notifications using this key.

For example, if you have a text secret with the identifier pagerdutykey, you can reference it like this:​

<+secrets.getValue("pagerdutykey")>​

You can reference a secret within the Org scope using an expression with org:

<+secrets.getvalue("org.your-secret-Id")>

You can reference a secret within the Account scope using an expression with account:

<+secrets.getvalue("account.your-secret-Id")>

You can copy or paste this key from PagerDuty's Configuration > Services > Service Details dialog > Integrations tab, as shown below.

For details, see PagerDuty's documentation on creating integrations.

Microsoft Teams notifications

For Microsoft Teams notifications, you enter in the Webhook URL for your Microsoft Teams channel in Microsoft Teams Webhook URL.

You create a channel connector in Microsoft Teams to generate the webhook Harness needs for notification.

In Microsoft Teams, right-click the channel where you want to send notifications, and select Connectors.

In Connectors, locate Incoming Webhook, and select Configure.

In Incoming Webhook, enter a name, such as Harness.

Right-click and save the Harness icon from here:

Select Upload Image and add the Harness icon you downloaded.

Next, you'll create the webhook URL needed by Harness.

In your Microsoft Teams connector, select Create. The webhook URL is generated.

Click the copy button to copy the webhook URL, and then select Done.

The channel indicates that the connector was set up.

In Harness, in Notification Method settings, enter the webhook URL for your Microsoft Teams channel in Microsoft Teams Webhook URL or add it as an encrypted text and reference it here.

For example, if you have a text secret with the identifier teamswebhookURL, you can reference it like this:​

<+secrets.getValue("teamswebhookURL")>​​

You can reference a secret within the Org scope using an expression with org:

<+secrets.getvalue("org.your-secret-Id")>​

You can reference a secret within the Account scope using an expression with account:​

<+secrets.getvalue("account.your-secret-Id")>​​

Webhook Notifications

Use Webhook notifications to inform an external application of an event.

Select the Webhook notification method, and then enter the URL to be called when the event occurs.

You can also use expressions to compose this URL. For example, https://companyurl.notify.com/execution=-<+pipeline.executionId>.

Note that the expression must be evaluated in the context of the event. For example, stage related expressions may not be valid for pipeline start events.

Add Custom Headers

Webhook notification method allows you to add custom headers consisting of key-value pairs.

Some important points to note:-

  1. You can add a header by clicking on + Add Header.
  2. You can delete a header by clicking on delete icon.
  3. A header can either be a Fixed value or an Expression.
  4. You can test your webhook integeration by clicking on Test.

Sample pipeline YAML with a webhook notification method, consisting of custom headers:-

notificationRules:
- name: test
identifier: test
pipelineEvents:
- type: AllEvents
- type: PipelineStart
- type: PipelineEnd
- type: PipelineSuccess
- type: PipelineFailed
- type: StageFailed
- type: StageSuccess
- type: StageStart
- type: StepFailed
notificationMethod:
type: Webhook
spec:
webhookUrl: https://app.harness.io/gateway/ng/api/projects/Quality_Assurence?accountIdentifier=vpCkHKsDSxK9_KYfjCTMKA&orgIdentifier=QE_Team
headers:
accept: "*/*"
authorization: <+pipeline.variables.sv1>
content-type: application/json
Status: <+pipeline.status>
Version: v1
Content-Encoding: gzip
Client-ID: <+pipeline.executionId>
If-Match: xyz
enabled: true
note

Please note that you should be able to include custom headers while creating custom webhook notifications channel(s) as well as while updating the existing ones.

For example, a Slack notification when the pipeline completes as well as when it is successful looks something like this:

The webhook call is made as a POST request, and includes a JSON object containing the properties of the triggered event.

JSON for webhook notifications

Here's the JSON Harness posts to your webhook endpoint.
{
"type": "object",
"properties": {
"accountIdentifier": {
"type": "string"
},
"orgIdentifier": {
"type": "string"
},
"projectIdentifier": {
"type": "string"
},
"pipelineIdentifier": {
"type": "string"
},
"planExecutionId": {
"type": "string"
},
"stageIdentifier": {
"type": "string"
},
"stepIdentifier": {
"type": "string"
},
"executionUrl": {
"type": "string"
},
"pipelineUrl": {
"type": "string"
},
"eventType": {
"type": "string",
"enum": [
"AllEvents",
"PipelineStart",
"PipelineSuccess",
"PipelineFailed",
"PipelineEnd",
"PipelinePaused",
"StageSuccess",
"StageFailed",
"StageStart",
"StepFailed"
]
},
"nodeStatus": {
"type": "string"
},
"triggeredBy": {
"type": "object",
"properties": {
"triggerType": {
"type": "string"
},
"name": {
"type": "string"
},
"email": {
"type": "string"
}
}
},
"moduleInfo": {
"type": "object",
"properties": {
"services": {
"type": "array",
"items": {
"type": "string"
}
},
"environments": {
"type": "array",
"items": {
"type": "string"
}
},
"envGroups": {
"type": "array",
"items": {
"type": "string"
}
},
"infrastructures": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"startTime": {
"type": "string"
},
"startTs": {
"type": "integer"
},
"endTime": {
"type": "string"
},
"endTs": {
"type": "integer"
}
}
}

Notify Slack channels in user groups

If you have Harness user groups that have Slack webhooks set up in their Notification Preferences, you can select those groups and Harness will notify them in addition to the Email, Slack, or PagerDuty settings.

Go to send notifications using Slack for more information.

Enable or disable notification rules

Once you've created notification rules, you can enable and disable them in the Notifications page.