# Comment and Label Matching
Beyond branch and event annotations, Pipelines-as-Code can trigger PipelineRuns based on comments or labels on pull requests. This is useful when you want human-initiated actions -- such as typing `/merge-pr` in a comment -- to kick off specific pipelines, or when you want labeling a pull request (for example, with `bug`) to automatically run a targeted test suite.

## Matching on a comment regex

> [!WARNING]
>
> **Matching PipelineRun on regex in comments** is a **Technology Preview** feature only.
> Technology Preview features are not currently supported and might not be functionally complete. We do not recommend using them in production. These features provide early access to upcoming Pipelines-as-Code features, enabling you to test functionality and provide feedback during the development process.

| Git Provider | Supported |
| --- | --- |
| GitHub App | ✅ |
| GitHub Webhook | ✅ |
| Forgejo | ✅ |
| GitLab | ✅ |
| Bitbucket Cloud | ❌ |
| Bitbucket Data Center | ❌ |


You can trigger a PipelineRun when someone posts a comment on a pull request or a [pushed commit](/nightly/docs/guides/gitops-commands/push-commands.md) by using the annotation `pipelinesascode.tekton.dev/on-comment`.

Pipelines-as-Code treats the annotation value as a regular expression (regex). It strips leading and trailing whitespace from the comment before matching, so `^` matches the start of the comment text and `$` matches the end.

Only newly created comments trigger matching. Edits or updates to existing comments do not trigger the PipelineRun.

Example:

```yaml
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: "merge-pr"
  annotations:
    pipelinesascode.tekton.dev/on-comment: "^/merge-pr"
```

Pipelines-as-Code triggers the `merge-pr` PipelineRun when a comment on a pull request starts with `/merge-pr`.

When the `on-comment` annotation triggers a PipelineRun, Pipelines-as-Code sets the template variable {{ trigger_comment }}. For details, see [Accessing the comment triggering the PipelineRun](/nightly/docs/guides/gitops-commands/advanced.md#accessing-the-comment-triggering-the-pipelinerun).

The `on-comment` annotation follows the pull_request [Policy](/nightly/docs/advanced/policy-authorization.md) rules. Only users listed in the pull_request policy can trigger the PipelineRun.

> [!NOTE]
>
> 
> The `on-comment` annotation works with pull_request events. For push events, Pipelines-as-Code supports it only [when targeting the main branch without arguments](/nightly/docs/guides/gitops-commands/push-commands.md).
> 
> Avoid using Pipelines-as-Code's built-in [GitOps commands](/nightly/docs/guides/gitops-commands.md) — such as `/test`, `/retest`, `/cancel`, or `/ok-to-test` — as `on-comment` patterns. These commands are processed before `on-comment` matching and can lead to unexpected behavior.
> 


## Matching on pull request labels

> [!WARNING]
>
> **Matching PipelineRun to a Pull-Request label** is a **Technology Preview** feature only.
> Technology Preview features are not currently supported and might not be functionally complete. We do not recommend using them in production. These features provide early access to upcoming Pipelines-as-Code features, enabling you to test functionality and provide feedback during the development process.

| Git Provider | Supported |
| --- | --- |
| GitHub App | ✅ |
| GitHub Webhook | ✅ |
| Forgejo | ✅ |
| GitLab | ✅ |
| Bitbucket Cloud | ❌ |
| Bitbucket Data Center | ❌ |


You can use the annotation `pipelinesascode.tekton.dev/on-label` to trigger a PipelineRun when a pull request carries a specific label. For example, to run the PipelineRun `match-bugs-or-defect` whenever a pull request has the label `bug` or `defect`:

```yaml
metadata:
  name: match-bugs-or-defect
  annotations:
    pipelinesascode.tekton.dev/on-label: "[bug, defect]"
    pipelinesascode.tekton.dev/on-target-branch: "[main]"
    pipelinesascode.tekton.dev/on-event: "[pull_request]"
```

* The `on-label` annotation respects the `pull_request` [Policy](/nightly/docs/advanced/policy-authorization.md) rules.
* You still need `on-target-branch` to specify which branch the pull request targets.
* You still need `on-event` to specify the event type.
* Pipelines-as-Code supports this annotation on GitHub, Forgejo, and GitLab only. Bitbucket Cloud and Bitbucket Data Center do not support pull request labels.
* When you add a label to a pull request, Pipelines-as-Code triggers the matching PipelineRun immediately and does not activate other PipelineRuns that match the same pull request.
* If you push a new commit to the pull request, Pipelines-as-Code triggers the label-matched PipelineRun again as long as the label is still present.
* You can access pull request labels with the [dynamic variable](/nightly/docs/guides/creating-pipelines.md#dynamic-variables) `{{ pull_request_labels }}`. Labels are separated by a Unix newline `\n`. For example, you can print them in a shell script:

  ```bash
   for i in $(echo -e "{{ pull_request_labels }}");do
   echo $i
   done
  ```

## Escaping commas in branch names

If a branch name contains a comma, use the HTML escape entity `&#44;` in place of the literal comma. For example, to match both `main` and a branch named `release,nightly`:

```yaml
pipelinesascode.tekton.dev/on-target-branch: [main, release&#44;nightly]
```


