Skip to content

Commit cdaf481

Browse files
Trigger API Documentation
Co-authored-by: Sascha Schwarze <[email protected]>
1 parent a5639bb commit cdaf481

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

docs/build.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ SPDX-License-Identifier: Apache-2.0
1717
- [Defining the Output](#defining-the-output)
1818
- [Defining Retention Parameters](#defining-retention-parameters)
1919
- [Defining Volumes](#defining-volumes)
20+
- [Defining Triggers](#defining-triggers)
2021
- [BuildRun deletion](#BuildRun-deletion)
2122

2223
## Overview
@@ -602,6 +603,109 @@ spec:
602603
name: test-config
603604
```
604605

606+
### Defining Triggers
607+
608+
Using the triggers, you can submit `BuildRun` instances when certain events happen. The idea is to be able to trigger Shipwright builds in an event driven fashion, for that purpose you can watch certain types of events.
609+
610+
**Note**: triggers rely on the [Shipwright Triggers](https://github.com/shipwright-io/triggers) project to be deployed and configured in the same Kubernetes cluster where you run Shipwright Build. If it is not set up, the triggers defined in a Build are ignored.
611+
612+
The types of events under watch are defined on the `.spec.trigger` attribute, please consider the following example:
613+
614+
```yaml
615+
apiVersion: shipwright.io/v1alpha1
616+
kind: Build
617+
spec:
618+
source:
619+
url: https://github.com/shipwright-io/sample-go
620+
contextDir: docker-build
621+
credentials:
622+
name: webhook-secret
623+
trigger:
624+
when: []
625+
```
626+
627+
Certain types of events will use attributes defined on `.spec.source` to complete the information needed in order to dispatch events.
628+
629+
#### GitHub
630+
631+
The GitHub type is meant to react upon events coming from GitHub WebHook interface, the events are compared against the existing `Build` resources, and therefore it can identify the `Build` objects based on `.spec.source.url` combined with the attributes on `.spec.trigger.when[].github`.
632+
633+
To identify a given `Build` object, the first criteria is the repository URL, and then the branch name listed on the GitHub event payload must also match. Following the criteria:
634+
635+
- First, the branch name is checked against the `.spec.trigger.when[].github.branches` entries
636+
- If the `.spec.trigger.when[].github.branches` is empty, the branch name is compared against `.spec.source.revision`
637+
- If `spec.source.revision` is empty, the default revision name is used ("main")
638+
639+
The following snippet shows a configuration machting `Push` and `PullRequest` events on the `main` branch, for example:
640+
641+
```yaml
642+
# [...]
643+
spec:
644+
source:
645+
url: https://github.com/shipwright-io/sample-go
646+
trigger:
647+
when:
648+
- name: push and pull-request on the main branch
649+
type: GitHub
650+
github:
651+
events:
652+
- Push
653+
- PullRequest
654+
branches:
655+
- main
656+
```
657+
658+
#### Image
659+
660+
In order to watch over images, in combination with the [Image](https://github.com/shipwright-io/image) controller, you can trigger new builds when those container image names change.
661+
662+
For instance, lets imagine the image named `ghcr.io/some/base-image` is used as input for the Build process and every time it changes we would like to trigger a new build. Please consider the following snippet:
663+
664+
```yaml
665+
# [...]
666+
spec:
667+
trigger:
668+
when:
669+
- name: watching for the base-image changes
670+
type: Image
671+
image:
672+
names:
673+
- ghcr.io/some/base-image:latest
674+
```
675+
676+
#### Tekton Pipeline
677+
678+
Shipwright can also be used in combination with [Tekton Pipeline](https://github.com/tektoncd/pipeline), you can configure the Build to watch for `Pipeline` resources in Kubernetes reacting when the object reaches the desired status (`.objectRef.status`), and is identified either by its name (`.objectRef.name`) or a label selector (`.objectRef.selector`). The example below uses the label selector approach:
679+
680+
```yaml
681+
# [...]
682+
spec:
683+
trigger:
684+
when:
685+
- name: watching over for the Tekton Pipeline
686+
type: Pipeline
687+
objectRef:
688+
status:
689+
- Succeeded
690+
selector:
691+
label: value
692+
```
693+
694+
While the next snippet uses the object name for identification:
695+
696+
```yaml
697+
# [...]
698+
spec:
699+
trigger:
700+
when:
701+
- name: watching over for the Tekton Pipeline
702+
type: Pipeline
703+
objectRef:
704+
status:
705+
- Succeeded
706+
name: tekton-pipeline-name
707+
```
708+
605709
### Sources
606710

607711
Sources represent remote artifacts, as in external entities added to the build context before the actual Build starts. Therefore, you may employ `.spec.sources` to download artifacts from external repositories.

0 commit comments

Comments
 (0)