Trigger a Deployment when a File Changes
File-based repo Triggers are currently supported only for Native Helm and Helm-based Kubernetes deployments. For more information, see Kubernetes or Helm?.For Build Workflows or a Build and Deploy Pipeline, you can trigger deployments in response to a Git event using Webhooks. This is described in Trigger Deployments using Git Events.
In some Webhook Trigger scenarios, you might set a Webhook on your repo to trigger a Workflow or Pipeline when a Push event occurs in the repo. However, you might want to initiate the Trigger only when specific files in the repo are changed.
For example, if you have a Trigger that executes a Helm Deployment workflow, and the Workflow uses a values.yaml file from a Git repo, you might want to initiate the Trigger only when that values.yaml file is changed.
This topic describes how to set up and run a file-based Trigger.
Before You Begin
In the Actions section of the Trigger, the Deploy only if files have changed option is displayed only if the following conditions are met:
- The Workflow selected deploys a Harness Kubernetes or Native Helm Service.
- The On Push event is selected.
For more information, see Kubernetes or Helm?.
Step 1: Create the Git Webhook Trigger
Follow the steps in Trigger Deployments using Git Events.
In Condition, select On Webhook Event.
In Payload Type, select the repository type (GitHub, Bitbucket, GitLab).
In Event Type, select the On Push Webhook event.
When you get to the Actions section, click Deploy only if files have changed.
The file-based, repo-related settings appear.
Step 2: Select the Files to Watch
In Git Connector, select which of the SourceRepro Providers set up in Harness to use. These are the connections between Harness and your Git repos. For more information, see Add SourceRepo Providers.
In Branch Name, enter the name of the branch to use.
In File Path, enter the file name for the file that, when changed and Pushed, will execute this Trigger.
For multiple file paths, use commas or line breaks as separators. For example,
Wildcards are not supported for Branch Name or File Path.
When you are done, the Skip deployment if file(s) not changed section will look something like this:
Click Next and then Submit.
Now you can add the Webhook for that Trigger to the repo you selected, as described in Trigger Deployments using Git Events.
When the file you entered is changed and Pushed, the Trigger will execute.
Review: Branch Regex Push and Pull
For merging changes, use the On Pull Request event type and not On Push. There is no source or destination in push. It has an old state and a new state. See Event Payloads from Atlassian.
The On Pull Request has a source and a destination branch. See Pull Request from Atlassian.
The following is a list of exactly which keys the On Pull Request and On Push events refer to:
- Github — push branch ref:
- Github — pull branch ref:
- GitLab — push branch ref:
- GitLab — pull branch ref:
- BitBucket — push branch ref:
- BitBucket — push branch ref on-premises:
- You must also select event type as
- You must also select event type as
- BitBucket — pull branch ref:
- BitBucket — pull branch ref on-premises:
- Passing Variables into Workflows from Triggers
- For information on using Triggers as part of Harness Git integration, see Onboard Teams Using Git.
- Trigger Deployments When a New Artifact is Added to a Repo
- Schedule Deployments using Triggers
- Trigger Deployments when Pipelines Complete
- Get Deployment Status using REST
- Trigger a Deployment using a URL
- Trigger Deployments using Git Events
- Trigger a Deployment using cURL
- Pause All Triggers using Deployment Freeze