Skip to content

Commit 8fcfe51

Browse files
chmouelclaude
andcommitted
fix: correct CEL expression syntax in filtering example
Fix syntax error in the CEL regex expression by separating the patterns into individual matches() calls connected with logical OR operators. This resolves the token recognition errors caused by unescaped pipe characters in the regex. Also added a warning about proper escaping of special characters in CEL expressions to help users avoid similar syntax errors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0cd9651 commit 8fcfe51

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

docs/content/docs/guide/matchingevents.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,18 +383,22 @@ This example demonstrates how to filter `pull_request` events to exclude changes
383383
pipelinesascode.tekton.dev/on-cel-expression: |
384384
event == "pull_request"
385385
&& target_branch == "main"
386-
&& !files.all.all(x, x.matches('^docs/|\\.md$|^(?:.*/)?(\.gitignore|OWNERS|PROJECT|LICENSE)$'))
386+
&& !files.all.all(x, x.matches('^docs/') || x.matches('\\.md$') || x.matches('(\\.gitignore|OWNERS|PROJECT|LICENSE)$'))
387387
```
388388

389389
This expression will:
390390

391391
* Only match `pull_request` events targeting the `main` branch
392392
* **Exclude** the PipelineRun if all changed files match any of the following patterns:
393393
* Files in the `docs/` directory (`^docs/`)
394-
* Markdown files (`.md$`)
395-
* Common repository metadata files (`.gitignore`, `OWNERS`, `PROJECT`, `LICENSE`)
394+
* Markdown files (`\\.md$`)
395+
* Common repository metadata files (`\\.gitignore`, `OWNERS`, `PROJECT`, `LICENSE`)
396396

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).
397+
The `!files.all.all(x, x.matches('pattern1') || x.matches('pattern2') || ...)` syntax means "not all files match any of these patterns", which effectively means "trigger only if at least one file doesn't match the exclusion patterns" (i.e., there are meaningful code changes).
398+
399+
{{< hint warning >}}
400+
**Important**: When using regex patterns in CEL expressions, remember to properly escape special characters. The backslash (`\`) needs to be doubled (`\\`) to escape properly within the CEL string context. Using logical OR (`||`) operators within the `matches()` function is more reliable than combining patterns with pipe (`|`) characters in a single regex.
401+
{{< /hint >}}
398402

399403
### Matching PipelineRun to an event (commit, pull_request) title
400404

0 commit comments

Comments
 (0)