You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using `{{ trigger_comment }}` in a PipelineRun YAML, GitHub
comments containing newlines (e.g., `/help`) can break YAML parsing due
to improper expansion.
This change replaces `\r\n` with `\n` in `trigger_comment`, similar to
how `pull_requests_labels` are handled. This ensures valid YAML
formatting and avoids parser errors.
Fixes#1929
Signed-off-by: Chmouel Boudjnah <[email protected]>
Copy file name to clipboardExpand all lines: docs/content/docs/guide/gitops_commands.md
+31-7
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ Roses are red, violets are blue. Pipelines are bound to flake by design.
31
31
32
32
{{< hint info >}}
33
33
34
-
Please be aware that GitOps commands such as `/test` and others will not function on closed Pull Requests or Merge Requests.
34
+
Please be aware that GitOps commands such as `/test` and others will not function on closed Pull Requests or Merge Requests.
35
35
36
36
{{< /hint >}}
37
37
@@ -87,21 +87,45 @@ The PipelineRun will be restarted regardless of the annotations if the comment `
87
87
88
88
## Accessing the Comment Triggering the PipelineRun
89
89
90
-
When you trigger a PipelineRun via a GitOps Command, the template variable `{{ trigger_comment }}` is set to the actual comment that triggered it.
90
+
When you trigger a PipelineRun via a GitOps Command, the template variable `{{
91
+
trigger_comment }}` is set to the actual comment that triggered it.
91
92
92
-
You can then perform actions based on the comment content with a shell script or other methods.
93
+
You can then perform actions based on the comment content with a shell script
94
+
or other methods.
93
95
94
-
There is a restriction with the `trigger_comment` variable: we modify it to replace newlines with `\n` since multi-line comments can cause issues when replaced inside the YAML.
96
+
Expanding `{{ trigger_comment }}` in YAML can break parsing if the comment
97
+
contains newlines. For example, a GitHub comment like:
95
98
96
-
It is up to you to replace it back with newlines. For example, with shell scripts, you can use `echo -e` to expand the newline back.
99
+
```console
100
+
/help
97
101
98
-
Example of a shell script:
102
+
This is a test.
103
+
```
104
+
105
+
Expands to:
106
+
107
+
```yaml
108
+
params:
109
+
- name: trigger_comment
110
+
value: "/help
111
+
112
+
This is a test."
113
+
```
114
+
115
+
The empty line makes the YAML invalid. To prevent this, we replace `\r\n` with
116
+
`\n`to ensure proper formatting.
117
+
118
+
You can restore the newlines in your task as needed.
119
+
120
+
For example, in a shell script, use `echo -e` to expand `\n` back into actual newlines:
99
121
100
122
```shell
101
123
echo -e "{{ trigger_comment }}" > /tmp/comment
102
-
grep "string" /tmp/comment
124
+
grep "/help" /tmp/comment # will output only /help
103
125
```
104
126
127
+
This ensures the comment is correctly formatted when processed.
128
+
105
129
## Custom GitOps Commands
106
130
107
131
Using the [on-comment]({{< relref "/docs/guide/matchingevents.md#matching-a-pipelinerun-on-a-regex-in-a-comment" >}}) annotation on your `PipelineRun`, you can define custom GitOps commands that will be triggered by comments on the Pull Request.
0 commit comments