Skip to content

Commit 0cd9651

Browse files
chmouelclaude
andcommitted
docs: add CEL filter example for non-code changes
Add comprehensive example showing how to use CEL expressions to filter PipelineRuns and exclude changes that only affect documentation, configuration files, or metadata files. This addresses user feedback about needing precise examples for crafting CEL regex expressions. The example demonstrates the !files.all.all() syntax to exclude PRs when all changes match patterns for docs/, .md files, and common metadata files like .gitignore, OWNERS, PROJECT, and LICENSE. Fixes: SRVKP-4602 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent 8cdbaff commit 0cd9651

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/content/docs/guide/matchingevents.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,27 @@ This example will match modified files with the name of test.go:
375375
files.modified.exists(x, x.matches('test.go'))
376376
```
377377

378+
### Filtering PipelineRuns to exclude non-code changes
379+
380+
This example demonstrates how to filter `pull_request` events to exclude changes that only affect documentation, configuration files, or other non-code files. This is useful when you want to run tests only when actual code changes occur:
381+
382+
```yaml
383+
pipelinesascode.tekton.dev/on-cel-expression: |
384+
event == "pull_request"
385+
&& target_branch == "main"
386+
&& !files.all.all(x, x.matches('^docs/|\\.md$|^(?:.*/)?(\.gitignore|OWNERS|PROJECT|LICENSE)$'))
387+
```
388+
389+
This expression will:
390+
391+
* Only match `pull_request` events targeting the `main` branch
392+
* **Exclude** the PipelineRun if all changed files match any of the following patterns:
393+
* Files in the `docs/` directory (`^docs/`)
394+
* Markdown files (`.md$`)
395+
* Common repository metadata files (`.gitignore`, `OWNERS`, `PROJECT`, `LICENSE`)
396+
397+
The `!files.all.all(x, x.matches('pattern'))` syntax means "not all files match the pattern", which effectively means "trigger only if at least one file doesn't match the exclusion pattern" (i.e., there are meaningful code changes).
398+
378399
### Matching PipelineRun to an event (commit, pull_request) title
379400

380401
This example will match all pull requests starting with the title `[DOWNSTREAM]`:

0 commit comments

Comments
 (0)