Create triggers
In Harness, you can create triggers to automatically run your CI/CD pipelines in response to push events in your Harness Code repos.
You can configure Harness Code webhook triggers in the visual or YAML editors.
- Visual
- YAML
- Go to the pipeline where you want to add a trigger for a Harness Code repository.
- Make sure your Harness Code repo is the pipeline's default codebase.
- Select Triggers in the Pipeline Studio header.
- Select New Trigger, and select the Harness webhook trigger type.
- Enter a trigger Name, select the Repository, Event, and Actions that you want the trigger to listen on, and, if desired, select specific stages to run for this trigger.
- On the Conditions tab, you can refine the trigger by specifying conditions that must also apply in addition to the previously-specified Event and Actions. For example, you can create a trigger that runs only when a Pull Request (event) is opened (action) against your
main
branch (condition). - On the Pipeline Input tab, if your pipeline accepts any runtime input, you can provide values that you want the trigger to use for these inputs.
- Save the trigger.
- To test the trigger, create a PR or push a change to your Code repository.
- Go to the pipeline where you want to add a trigger for a Harness Code repository.
- Make sure your Harness Code repo is the pipeline's default codebase.
- Select Triggers in the Pipeline Studio header.
- Select New Trigger, and select the Harness webhook trigger type.
- Enter a trigger Name and then switch to the YAML editor.
- Configure the trigger settings as described in Trigger pipelines using Git events and Webhook triggers reference.
- Save the trigger.
- To test the trigger, create a PR or push a change to your Code repository.
Here's a Harness Code webhook trigger YAML example. This trigger listens for Pull Requests to be opened, reopened, or edited in a specific Harness Code repo. In addition, it only triggers if the PR's target branch is main
.
trigger:
name: YOUR_TRIGGER_NAME
identifier: yourtriggerid
enabled: true
description: ""
tags: {}
orgIdentifier: YOUR_HARNESS_ORG_ID
stagesToExecute: []
projectIdentifier: YOUR_HARNESS_PROJECT_ID
pipelineIdentifier: YOUR_PIPELINES_ID
source:
type: Webhook
spec:
type: Harness
spec:
type: PullRequest ## Specify the event type to listen on.
spec:
connectorRef: ""
autoAbortPreviousExecutions: true ## If true, in-progress builds previously started by this trigger are cancelled when another build is initiated by this trigger. Minimizes concurrent builds for frequently activated triggers.
payloadConditions: ## Conditions are an optional way to refine triggers beyond 'type' and 'actions'.
- key: targetBranch
operator: Equals
value: main
headerConditions: []
repoName: YOUR_HARNESS_CODE_REPO_NAME
actions: ## Specify the actions to listen on for the specified event 'type'.
- Open
- Reopen
- Edit
inputYaml: | ## If required, specify input to supply to the build at runtime.
pipeline:
identifier: YOUR_HARNESS_PIPELINE_ID
properties:
ci:
codebase:
build:
type: PR
spec:
number: <+trigger.prNumber>
Permissions required for creating and updating Triggers
Triggers creation are supported with two modes of permissions
- Mandatory Mode : Users need both pipeline creation/editing and pipeline execution permissions.
- Optional Mode : Users can create/edit pipelines and execute them, but it's not mandatory.
This can be enabled using the settings available at Project level as part of the pipeline settings group
You have the option to turn off the necessary permissions for creating or editing pipelines in order to manage triggers separately. By doing this, you can allow only specific users to edit the pipeline while still enabling them to create or update triggers.