Trigger Deployments using Git Events
- Before You Begin
- Limitations
- Review: Git Webhook Triggers
- Step 1: Add a Trigger
- Step 2: Select Repo and Event Type
- Review: Payload and Event Type Matrix
- Step 3: Select the Workflow or Pipeline to Deploy
- Step 4: Provide Values for Workflow Variables
- Step 5: Select the Artifact to Deploy
- Option: Manual Triggers
- Step 6: Set Up the Github Webhook
- Configure As Code
- Related Topics
For GitHub, GitLab, and Bitbucket, you can trigger Build Workflows or a Build and Deploy Pipeline in response to a Git event using Webhooks using a Harness On Webhook Event Trigger.
For example, the first stage of the Build and Deploy Pipeline is a Build Workflow that builds the artifact from a Git repo. You can set a Harness Trigger to run once the artifact is built.
For Custom Git providers, you can trigger any type of Harness Workflow using a Harness On Webhook Event Trigger.
In this topic:
- Before You Begin
- Limitations
- Review: Git Webhook Triggers
- Step 1: Add a Trigger
- Step 2: Select Repo and Event Type
- Review: Payload and Event Type Matrix
- Step 3: Select the Workflow or Pipeline to Deploy
- Step 4: Provide Values for Workflow Variables
- Step 5: Select the Artifact to Deploy
- Option: Manual Triggers
- Step 6: Set Up the Github Webhook
- Configure As Code
- Related Topics
Before You Begin
Limitations
In the Actions section of the Trigger, the Deploy only if files have changed option is available for Workflows deploying Kubernetes or Native Helm Services only.
Review: Git Webhook Triggers
You can create Harness Triggers that respond to certain Git events, and then add the Harness Trigger Git Webhook to your repo. When the specified event happens in your repo, the Harness Trigger is run.
Let's review Git Webhooks.
GitHub, GitLab, and Bitbucket Webhook-based Triggers are not intended for Workflows and Pipelines that deploy artifacts. They are designed for Build Workflows and Pipelines that build artifacts in response to Gt events.
Git Webhooks allow you to build or set up apps which subscribe to certain events in your git repo on github.com, bitbucket.org, and gitlab.com.
Each event corresponds to a certain set of actions that can happen to your organization and/or repository.
When one of those events is triggered, Git sends a HTTP POST payload to the Webhook's configured URL.
You can use a Harness Trigger GitHub/Bitbucket/Gitlab Webhook URL and execute a Harness deployment in response to a Git event.
The most common example: A Git event that merges code initiates the Trigger for a Harness Build and Deploy Pipeline.
The first stage of the Pipeline is a Build Workflow that builds and collects the artifact from the Artifact Source (which is linked to the Git repo). The final stage deploys the newly built artifact from the artifact source.
Step 1: Add a Trigger
Typically, Triggers are set up after you have successfully deployed and tested a Workflow or Pipeline.
To add a trigger, do the following:
- Ensure that you have a Harness Service, Environment, and Workflow set up. If you want to Trigger a Pipeline, you'll need one set up also.
- In your Harness Application, click Triggers.
- Click Add Trigger. The Trigger settings appear.
- In Name, enter a name for the Trigger. This name will appear in the Deployments page to indicate the Trigger that initiated a deployment.
- Click Next.
Step 2: Select Repo and Event Type
A Git event that merges code initiates the Trigger for the Build and Deploy Pipeline.
The first stage of the Pipeline is a Build Workflow that builds and collects the artifact from the Artifact Source (which is linked to the Git repo).
In the Actions section, you select the Git repo provider and the event type you want to run the Trigger.
- In Condition, select On Webhook Event.
- In Payload Type, select the repository type (GitHub, Bitbucket, GitLab).
- In Event Type, select the event type for the Webhook event.
There are different options depending on the repo selected in Payload Type. See Review: Payload and Event Type Matrix below.
If you are using a repo other than GitHub, Bitbucket, or Gitlab (such as Jenkins or Bamboo), leave the Payload Type menu blank.
Harness will still generate a Webhook that you can use in your repo.
Review: Payload and Event Type Matrix
The following table displays the payload and event types supported when you select the On Webhook Event option in a Trigger's Condition setting.
For details on each event type and its actions, please consult the provider's documentation.
Payload Type |
Event Type |
BitBucket |
On Pull Request On Repository On Issue |
GitHub |
On Pull Request On Push On Delete On Release On Package |
GitLab |
On Pull Request On Push |
Custom or no selection. This option is for repos other than the default Git providers. For example, Bamboo or Jenkins. |
On Pull Request On Push |
Step 3: Select the Workflow or Pipeline to Deploy
For GitHub, GitLab, and Bitbucket, you can trigger Build Workflows or a Build and Deploy Pipeline in response to a Git event using Webhooks using a Harness On Webhook Event Trigger.
For Custom Git providers, you can trigger any type of Workflow using a Harness Trigger.
- In Execution Type, select Workflow or Pipeline.
- In Execute Workflow/Pipeline, select the Workflow or Pipeline to deploy.
Step 4: Provide Values for Workflow Variables
If the Workflow or Pipeline you selected to deploy uses Workflow variables, you will need to provide values for these variables.
You can also use variable expressions for these values. See Passing Variables into Workflows from Triggers.
Step 5: Select the Artifact to Deploy
Since Workflows deploy Harness Services, you are also prompted to provide the Artifact Source for the Service(s) the Workflow(s) will deploy.
There are three main settings:
From Triggering Artifact Source
Select this option to use the artifact identified in Artifact Source you selected in Condition.
Last Collected
Select this option to use the last artifact collected by Harness in the Harness Service. Artifact metadata is collected automatically every minute by Harness.
You can also manually collect artifact metadata using the Service's Manually pull artifact feature.
Last Successfully Deployed
The last artifact that was deployed by the Workflow you select.
Option: Manual Triggers
You can manually deploy a Harness Workflow or Pipeline using a Manual Trigger. You can run a Trigger manually in the following ways:
- Using a URL provided by Harness.
- Using a curl command.
- Use a REST call to get deployment status.
See the following:
Step 6: Set Up the Github Webhook
Once your On Webhook Event Trigger is completed, the next step is to integrate it into your Git repo so that the Trigger is executed in response to the Git event.
- In your Harness application, click Triggers.
- In the bottom of each listed Trigger is a link for GitHub Webhook.
- For the Trigger you want to use, click GitHub Webhook. The Trigger dialog appears.
- Copy the Webhook and use it in GitHub to trigger the deployment.
- Add the webhook to your Git repo.
In GitHub and the other Git repos, when configuring the Webhook, you can choose which events you would like to receive payloads for. You can even opt-in to all current and future events. - In Content type, ensure you select application/json.
Just the Push Event | Pushes and Pull Requests |
![]() | ![]() |
Configure As Code
To see how to configure the settings in this topic using YAML, configure the settings in the UI first, and then click the YAML editor button (</>).
Related Topics
- Passing Variables into Workflows from Triggers
- For information on using Triggers as part of Harness GitOps, see Harness GitOps.
- Trigger Deployments When a New Artifact is Added to a Repo
- Schedule Deployments using Triggers
- Trigger Deployments when Pipelines Complete
- Trigger a Deployment using cURL
- Trigger a Deployment when a File Changes
- Get Deployment Status using REST
- Pause All Triggers using Deployment Freeze