> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/harness-platform/knowledge-base-and-faqs/articles/trigger-deployments-when-pipelines-complete-in-next-gen.md).

# Trigger Deployments when Pipelines Complete in NextGen

This section describes how to trigger deployments or a pipeline after the completion of another pipeline.

### Problem Statement <a href="#problem-statement" id="problem-statement"></a>

How can I trigger deployments or a pipeline after the completion of another pipeline?

### Resolution <a href="#resolution" id="resolution"></a>

You can trigger Harness Pipeline deployments when specific Harness Pipelines complete their deployments.

For example, you might create a Pipeline to test a deployment in one environment. When it completes its deployment, a Trigger executes a second Pipeline to deploy to your stage environment.

The solution involves automating the triggering of a pipeline upon the successful completion of another pipeline by using custom triggers and webhooks. Here's a breakdown:

#### 1. **Create a Custom Trigger in the Target Pipeline:** <a href="#id-1-create-a-custom-trigger-in-the-target-pipeline" id="id-1-create-a-custom-trigger-in-the-target-pipeline"></a>

* **Target Pipeline:** This is the pipeline that you want to start automatically after the completion of another pipeline (the source pipeline).
* **Custom Trigger:** A custom trigger is set up in the target pipeline, which listens for specific events (like a webhook call) to start the pipeline. This trigger can be configured to start the pipeline when it receives a specific request or notification.
* **Custom Webhook Trigger** <https://developer.harness.io/docs/platform/triggers/custom-trigger-passing-data>

#### 2. **Add a Webhook Notification in the Source Pipeline:** <a href="#id-2-add-a-webhook-notification-in-the-source-pipeline" id="id-2-add-a-webhook-notification-in-the-source-pipeline"></a>

* **Source Pipeline:** This is the pipeline that, once it finishes, should trigger the target pipeline.
* **Webhook Notification:** A webhook is a way for an application to send real-time data to other applications. In this case, when the source pipeline finishes, it sends a webhook notification.
* **Passing the Custom Trigger URL:** The webhook notification includes the URL of the custom trigger created in the target pipeline. This URL is the endpoint that the webhook will hit to trigger the target pipeline.
* **Passing Token (if mandatory):** Some systems require authentication for security reasons. If the custom trigger requires authentication, you would pass a token as part of the request header in the webhook. This token is often stored as a secret to keep it secure.
* **Webhook Notifications:** <https://developer.harness.io/docs/platform/notifications/notifications/configure-notifications#configure-pipeline-notifications>

#### **Workflow Summary:** <a href="#workflow-summary" id="workflow-summary"></a>

1. **Setup the Custom Trigger:** In the target pipeline, create a custom trigger that listens for a webhook event.
2. **Configure the Source Pipeline:** Add a webhook notification to the source pipeline that will be triggered upon its completion.
3. **Trigger the Target Pipeline:** When the source pipeline finishes, it sends a webhook request to the custom trigger URL of the target pipeline. If required, it includes a secret token for authentication.
4. **Target Pipeline Starts:** The target pipeline starts executing based on the custom trigger's configuration.

This setup ensures that the target pipeline automatically runs after the successful completion of the source pipeline, creating a seamless automation flow between the two pipelines.
