Skip to content

Commit b0359e1

Browse files
authored
Merge pull request #88596 from mramendi/RHDEVDOCS-6346
RHDEVDOCS 6346 configure PAC pipeline run cancel-in-progress, plus mo…
2 parents 9af782a + aa7ccec commit b0359e1

5 files changed

+154
-94
lines changed

modules/op-creating-pipeline-run-using-pipelines-as-code.adoc renamed to modules/op-matching-pipeline-run-using-pipelines-as-code.adoc

Lines changed: 23 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,13 @@
22
// * pac/managing-pipeline-runs-pac.adoc
33

44
:_mod-docs-content-type: REFERENCE
5-
[id="creating-pipeline-run-using-pipelines-as-code_{context}"]
6-
= Creating a pipeline run using {pac}
5+
[id="matching-pipeline-run-using-pipelines-as-code_{context}"]
6+
= Annotations for matching events to a pipeline run
77

8-
[role="_abstract"]
9-
To run pipelines using {pac}, you can create pipeline run definitions or templates as YAML files in the `.tekton/` directory of the repository. You can reference YAML files in other repositories using remote URLs, but pipeline runs are only triggered by events in the repository containing the `.tekton/` directory.
8+
You can match different Git provider events with each pipeline run by using annotations on the pipeline run. If there are multiple pipeline runs matching an event, {pac} runs them in parallel and posts the results to the Git provider as soon as a pipeline run finishes.
109

11-
The {pac} resolver bundles the pipeline runs with all tasks as a single pipeline run without external dependencies.
12-
13-
[NOTE]
14-
====
15-
* For pipelines, use at least one pipeline run with a spec, or a separated `Pipeline` object.
16-
* For tasks, embed task spec inside a pipeline, or define it separately as a Task object.
17-
====
18-
19-
[discrete]
20-
.Parameterizing commits and URLs
21-
22-
You can specify the parameters of your commit and URL by using dynamic, expandable variables with the {{<var>}} format. Currently, you can use the following variables:
23-
24-
* `{{repo_owner}}`: The repository owner.
25-
* `{{repo_name}}`: The repository name.
26-
* `{{repo_url}}`: The repository full URL.
27-
* `{{revision}}`: Full SHA revision of a commit.
28-
* `{{sender}}`: The username or account id of the sender of the commit.
29-
* `{{source_branch}}`: The branch name where the event originated.
30-
* `{{target_branch}}`: The branch name that the event targets. For push events, it's the same as the `source_branch`.
31-
* `{{pull_request_number}}`: The pull or merge request number, defined only for a `pull_request` event type.
32-
* `{{git_auth_secret}}`: The secret name that is generated automatically with Git provider's token for checking out private repos.
33-
34-
[discrete]
35-
.Matching an event to a pipeline run
36-
37-
You can match different Git provider events with each pipeline run by using special annotations on the pipeline run. If there are multiple pipeline runs matching an event, {pac} runs them in parallel and posts the results to the Git provider as soon a pipeline run finishes.
38-
39-
[discrete]
40-
.Matching a pull event to a pipeline run
10+
[id="pull-matching-pipeline-run-using-pipelines-as-code_{context}"]
11+
== Matching a pull request event to a pipeline run
4112

4213
You can use the following example to match the `pipeline-pr-main` pipeline run with a `pull_request` event that targets the `main` branch:
4314

@@ -52,13 +23,13 @@ annotations:
5223
pipelinesascode.tekton.dev/on-event: "[pull_request]"
5324
# ...
5425
----
55-
<1> You can specify multiple branches by adding comma-separated entries. For example, `"[main, release-nightly]"`. In addition, you can specify the following:
26+
<1> You can specify multiple branches by adding comma-separated entries. For example, `"[main, release-nightly]"`. In addition, you can specify the following items:
5627
* Full references to branches such as `"refs/heads/main"`
5728
* Globs with pattern matching such as `"refs/heads/\*"`
5829
* Tags such as `"refs/tags/1.\*"`
5930

60-
[discrete]
61-
.Matching a push event to a pipeline run
31+
[id="push-matching-pipeline-run-using-pipelines-as-code_{context}"]
32+
== Matching a push event to a pipeline run
6233

6334
You can use the following example to match the `pipeline-push-on-main` pipeline run with a `push` event targeting the `refs/heads/main` branch:
6435

@@ -73,13 +44,17 @@ annotations:
7344
pipelinesascode.tekton.dev/on-event: "[push]"
7445
# ...
7546
----
76-
<1> You can specify multiple branches by adding comma-separated entries. For example, `"[main, release-nightly]"`. In addition, you can specify the following:
47+
<1> You can specify multiple branches by adding comma-separated entries. For example, `"[main, release-nightly]"`. In addition, you can specify the following items:
7748
* Full references to branches such as `"refs/heads/main"`
7849
* Globs with pattern matching such as `"refs/heads/\*"`
7950
* Tags such as `"refs/tags/1.\*"`
8051

81-
[discrete]
82-
.Matching a pull request label to a pipeline run
52+
[id="label-matching-pipeline-run-using-pipelines-as-code_{context}"]
53+
== Matching a pull request label to a pipeline run
54+
55+
:FeatureName: Matching pull request labels to a pipeline run
56+
include::snippets/technology-preview.adoc[]
57+
8358

8459
// Note for reviewers: passive voice unfortunately seems to be necessary in the following paragraph. A label can be added to a pull request by an automated system as well as a user, so there is no subject to mention. The same applies to updating the PR with a new commit
8560

@@ -103,11 +78,11 @@ annotations:
10378
The current version of {pac} supports matching events to pull request labels only for the GitHub, Gitea, and GitLab repository hosting service providers.
10479
====
10580

106-
:FeatureName: Matching pull request labels a pipeline run
107-
include::snippets/technology-preview.adoc[]
81+
[id="comment-matching-pipeline-run-using-pipelines-as-code_{context}"]
82+
== Matching a comment event to a pipeline run
10883

109-
[discrete]
110-
.Matching a comment event to a pipeline run
84+
:FeatureName: Matching a comment event to a pipeline run
85+
include::snippets/technology-preview.adoc[]
11186

11287
You can use the following example to match the `pipeline-comment` pipeline run with a comment on a pull request, when the text of the comment matches the `^/merge-pr` regular expression:
11388

@@ -129,11 +104,8 @@ The pipeline run starts only if the comment author meets one of the following re
129104
* The author is a public member on the organization of the repository.
130105
* The comment author is listed in the `approvers` or `reviewers` section of the `OWNERS` file in the root of the repository, as defined in the https://www.kubernetes.dev/docs/guide/owners/[Kubernetes documentation]. {pac} supports the specification for the `OWNERS` and `OWNERS_ALIASES` files. If the `OWNERS` file includes a https://github.com/kubernetes/community/blob/master/contributors/guide/owners.md#filters[filters] section, {pac} matches approvers and reviewers only against the `.*` filter.
131106

132-
:FeatureName: Matching a comment event to a pipeline run
133-
include::snippets/technology-preview.adoc[]
134-
135-
[discrete]
136-
.Advanced event matching
107+
[id="advanced-matching-pipeline-run-using-pipelines-as-code_{context}"]
108+
== Advanced event matching
137109

138110
{pac} supports using Common Expression Language (CEL) based filtering for advanced event matching. If you have the `pipelinesascode.tekton.dev/on-cel-expression` annotation in your pipeline run, {pac} uses the CEL expression and skips the `on-target-branch` annotation. Compared to the simple `on-target-branch` annotation matching, the CEL expressions allow complex filtering and negation.
139111

@@ -230,53 +202,12 @@ metadata:
230202

231203
[NOTE]
232204
====
233-
If you use the `header` or `body` field for event matching, you might be unable to trigger the pipeline run using Git commands such as `retest`. If you use a Git command, the payload body is the comment that contains this command and not the original payload.
205+
If you use the `header` or `body` field for event matching, you might be unable to trigger the pipeline run using Git commands such as `retest`. If you use a Git command, the payload body is the comment that contains this command, and not the original payload.
234206
235-
If you want to trigger the pipeline run again when using the `body` field for event matching, you can close and reopen the pull request or merge request, or alternatively add a new SHA commit, for example using the following command:
207+
If you want to trigger the pipeline run again when using the `body` field for event matching, you can close and reopen the pull request or merge request, or alternatively add a new SHA commit. You can add a new SHA commit by using the following command:
236208
237209
[source,terminal]
238210
----
239211
git commit --amend --no-edit && git push --force-with-lease
240212
----
241213
====
242-
243-
[discrete]
244-
.Using the temporary GitHub App token for Github API operations
245-
246-
You can use the temporary installation token generated by {pac} from GitHub App to access the GitHub API. The token value is stored in the temporary `{{git_auth_secret}}` dynamic variable generated for private repositories in the `git-provider-token` key.
247-
248-
For example, to add a comment to a pull request, you can use the `github-add-comment` task from {tekton-hub} using a {pac} annotation:
249-
250-
[source,yaml]
251-
----
252-
...
253-
pipelinesascode.tekton.dev/task: "github-add-comment"
254-
...
255-
----
256-
257-
You can then add a task to the `tasks` section or `finally` tasks in the pipeline run definition:
258-
259-
[source,yaml]
260-
----
261-
[...]
262-
tasks:
263-
- name:
264-
taskRef:
265-
name: github-add-comment
266-
params:
267-
- name: REQUEST_URL
268-
value: "{{ repo_url }}/pull/{{ pull_request_number }}" <1>
269-
- name: COMMENT_OR_FILE
270-
value: "Pipelines as Code IS GREAT!"
271-
- name: GITHUB_TOKEN_SECRET_NAME
272-
value: "{{ git_auth_secret }}"
273-
- name: GITHUB_TOKEN_SECRET_KEY
274-
value: "git-provider-token"
275-
...
276-
----
277-
<1> By using the dynamic variables, you can reuse this snippet template for any pull request from any repository.
278-
279-
[NOTE]
280-
====
281-
On GitHub Apps, the generated installation token is available for 8 hours and scoped to the repository from where the events originate unless configured differently on the cluster.
282-
====
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// This module is included in the following assemblies:
2+
// * pac/managing-pipeline-runs-pac.adoc
3+
4+
:_mod-docs-content-type: REFERENCE
5+
[id="parameters-pipeline-run-using-pipelines-as-code_{context}"]
6+
= Parameters in a pipeline run specification
7+
8+
You can use parameters in a pipeline run specification to provide information about the commit that triggered the pipeline run and to use the temporary GitHub App token for Github API operations.
9+
10+
[id="commits-parameters-pipeline-run-using-pipelines-as-code_{context}"]
11+
== Commit and URL information
12+
13+
You can specify the parameters of your commit and URL by using dynamic, expandable variables with the `{{<var>}}` format. Currently, you can use the following variables:
14+
15+
* `{{repo_owner}}`: The repository owner.
16+
* `{{repo_name}}`: The repository name.
17+
* `{{repo_url}}`: The repository full URL.
18+
* `{{revision}}`: Full SHA revision of a commit.
19+
* `{{sender}}`: The username or account ID of the sender of the commit.
20+
* `{{source_branch}}`: The branch name where the event originated.
21+
* `{{target_branch}}`: The branch name that the event targets. For push events, it is the same as the `source_branch`.
22+
* `{{pull_request_number}}`: The pull or merge request number, defined only for a `pull_request` event type.
23+
* `{{git_auth_secret}}`: The secret name that is generated automatically with the Git provider token for checking out private repos.
24+
25+
[id="token-parameters-pipeline-run-using-pipelines-as-code_{context}"]
26+
== Temporary GitHub App token for GitHub API operations
27+
28+
You can use the temporary installation token generated by {pac} from the GitHub App to access the GitHub API. The GitHub App generates a key for private repositories in the `git-provider-token` key. You can use the `{{git_auth_secret}}` dynamic variable in pipeline runs to access this key.
29+
30+
For example, if your pipeline run must add a comment to a pull request, you can use the a {pac} annotation to fetch the `github-add-comment` task definition from {tekton-hub}, and then define the task that adds the comment, as shown in the following example:
31+
32+
[source,yaml]
33+
----
34+
apiVersion: tekton.dev/v1
35+
kind: PipelineRun
36+
metadata:
37+
name: pipeline-with-comment
38+
annotations:
39+
pipelinesascode.tekton.dev/task: "github-add-comment"
40+
spec:
41+
pipelineSpec:
42+
tasks:
43+
- name: add-sample-comment
44+
taskRef:
45+
name: github-add-comment
46+
params:
47+
- name: REQUEST_URL
48+
value: "{{ repo_url }}/pull/{{ pull_request_number }}" <1>
49+
- name: COMMENT_OR_FILE
50+
value: "Pipelines as Code IS GREAT!"
51+
- name: GITHUB_TOKEN_SECRET_NAME
52+
value: "{{ git_auth_secret }}"
53+
- name: GITHUB_TOKEN_SECRET_KEY
54+
value: "git-provider-token"
55+
----
56+
<1> By using the dynamic variables, you can reuse this snippet template for any pull request from any repository that you use with {pac}.
57+
58+
[NOTE]
59+
====
60+
On GitHub Apps, the generated installation token is available for 8 hours and scoped to the repository from where the events originate. You can configure the scope differently, but the expiration time is determined by GitHub.
61+
====
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This module is included in the following assemblies:
2+
// * pac/managing-pipeline-runs-pac.adoc
3+
4+
:_mod-docs-content-type: REFERENCE
5+
[id="params-annots-pipeline-run-using-pipelines-as-code_{context}"]
6+
= Parameters and annotations in a {pac} pipeline run
7+
8+
// Note for reviewers: some of the information in this file is to be moved into a separate procedure in the next pull request, which will require a separate review cycle.
9+
10+
[role="_abstract"]
11+
To run pipelines using {pac}, you can create pipeline run definitions or templates as YAML files in the `.tekton/` directory of your Git repository. You can reference YAML files in other repositories using remote URLs, but pipeline runs are triggered only by events in the repository containing the `.tekton/` directory.
12+
13+
The {pac} resolver bundles the pipeline runs with all tasks as a single pipeline run without external dependencies.
14+
15+
In addition to features that exist in all {openshift-pipelines} pipeline runs, you can use additional parameters and annotations in pipeline run files for {pac}.
16+
17+
[NOTE]
18+
====
19+
* For pipelines, use at least one pipeline run with a spec, or a separated `Pipeline` object.
20+
* For tasks, embed the task specification inside a pipeline, or define it separately as a Task object.
21+
====
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This module is included in the following assemblies:
2+
// * pac/managing-pipeline-runs-pac.adoc
3+
4+
:_mod-docs-content-type: REFERENCE
5+
[id="speccancel-pipeline-run-using-pipelines-as-code_{context}"]
6+
= Annotations for specifying automatic cancellation-in-progress for a pipeline run
7+
8+
By default, {pac} does not cancel pipeline runs automatically. Every pipeline run that {pac} creates and starts executes until it completes. However, events that trigger pipeline runs can come in quick succession. For example, if a pull request triggers a pipeline run and then the user pushes new commits into the pull request source branch, each push triggers a new copy of the pipeline run. If several pushes happen, several copies can run, which can consume excessive cluster resources.
9+
10+
You can configure a pipeline run to enable automatic cancellation-in-progress. If you enable automatic cancellation for a pipeline run, {pac} cancels the pipeline run in the following situations:
11+
12+
* {pac} has successfully started a copy of the same pipeline run for the same pull request or the same source branch.
13+
14+
* The pull request that triggered the pipeline run is merged or closed.
15+
16+
You can use the following example to enable automatic cancellation when you create the `sample-pipeline` pipeline run:
17+
18+
[source,yaml]
19+
----
20+
apiVersion: tekton.dev/v1
21+
kind: PipelineRun
22+
metadata:
23+
name: sample-pipeline
24+
annotations:
25+
pipelinesascode.tekton.dev/cancel-in-progress: "true"
26+
# ...
27+
----
28+
29+
[NOTE]
30+
====
31+
{pac} cancels a pipeline run _after_ starting a new copy of this pipeline run successfully. The `pipelinesascode.tekton.dev/cancel-in-progress` setting does _not_ ensure that only one copy of the pipeline run is executing at any time.
32+
====
33+
34+
:FeatureName: Automatic cancellation-in-progress of pipeline runs
35+
include::snippets/technology-preview.adoc[]

pac/managing-pipeline-runs-pac.adoc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,24 @@ toc::[]
99
[role="_abstract"]
1010
Using {pac}, you can create pipelines in your code repository and run these pipelines.
1111

12-
include::modules/op-creating-pipeline-run-using-pipelines-as-code.adoc[leveloffset=+1]
12+
include::modules/op-params-annots-pipeline-run-using-pipelines-as-code.adoc[leveloffset=+1]
13+
include::modules/op-parameters-pipeline-run-using-pipelines-as-code.adoc[leveloffset=+2]
1314

15+
[role="_additional-resources"]
16+
[id="additional-resources-parameters-pipelinerun_{context}"]
17+
.Additional resources
18+
* xref:../pac/using-pipelines-as-code-repos.adoc#scoping-github-token_using-pipelines-as-code-repos[Scoping the GitHub token to additional repositories]
19+
20+
include::modules/op-matching-pipeline-run-using-pipelines-as-code.adoc[leveloffset=+2]
21+
22+
[role="_additional-resources"]
23+
[id="additional-resources-matching-pipelinerun_{context}"]
1424
.Additional resources
1525

1626
* link:https://github.com/google/cel-spec/blob/master/doc/langdef.md[CEL language specification]
1727
28+
include::modules/op-speccancel-pipeline-run-using-pipelines-as-code.adoc[leveloffset=+2]
29+
1830
include::modules/op-running-pipeline-run-using-pipelines-as-code.adoc[leveloffset=+1]
1931

2032
include::modules/op-restarting-or-canceling-pipeline-run-using-pipelines-as-code.adoc[leveloffset=+1]
@@ -36,7 +48,7 @@ include::modules/op-cleaning-up-pipeline-run-using-pipelines-as-code.adoc[levelo
3648
include::modules/op-using-incoming-webhook-with-pipelines-as-code.adoc[leveloffset=+1]
3749

3850
[role="_additional-resources"]
39-
[id="additional-resources-pac_managing"]
51+
[id="additional-resources-pac_managing_{context}"]
4052
== Additional resources
4153

4254
* link:https://github.com/openshift-pipelines/pipelines-as-code/tree/main/.tekton[An example of the `.tekton/` directory in the Pipelines as Code repository]

0 commit comments

Comments
 (0)