Skip to content

Commit 15304e2

Browse files
committed
Trigger API Documentation
1 parent 80dbbeb commit 15304e2

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

docs/build.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,103 @@ spec:
602602
name: test-config
603603
```
604604

605+
### Defining Triggers
606+
607+
Using the [triggers](https://github.com/shipwright-io/triggers) application you can issue `BuildRun` instances when certain events happen. The idea is to be able to trigger Shipwright builds in a event driven fashion, for that purpose you can watch certain types of events.
608+
609+
The types of events under watch are defined on the `.spec.trigger` attribute, please consider the following example:
610+
611+
```yaml
612+
apiVersion: shipwright.io/v1alpha1
613+
kind: Build
614+
spec:
615+
source:
616+
url: https://github.com/shipwright-io/sample-go
617+
contextDir: docker-build
618+
credentials:
619+
name: webhook-secret
620+
trigger:
621+
when: []
622+
```
623+
624+
Certain types of events will use attributes defined on `.spec.source` to complete the information needed in order to dispatch events.
625+
626+
#### GitHub
627+
628+
The GitHub type is meant to react on events coming from GitHub WebHook, the events are compared against the existing `Build` resources and therefore it can find `Build` based on `.spec.source.url` combined with the attributes on `.spec.trigger.when[].github`.
629+
630+
When `.spec.trigger.when[].github.branches` is empty, the `.spec.source.revision` is employed, the default "branch" name employed is based on the regular source repository configuration.
631+
632+
The folowing snippet shows a configuration machting `Push` and `PullRequest` events on the `main` branch, for example:
633+
634+
```yaml
635+
# [...]
636+
spec:
637+
source:
638+
url: https://github.com/shipwright-io/sample-go
639+
trigger:
640+
when:
641+
- name: push and pull-request on the main branch
642+
type: GitHub
643+
github:
644+
events:
645+
- Push
646+
- PullRequest
647+
branches:
648+
- main
649+
```
650+
651+
#### Image
652+
653+
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.
654+
655+
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:
656+
657+
```yaml
658+
# [...]
659+
spec:
660+
trigger:
661+
when:
662+
- name: watching for the base-image changes
663+
type: Image
664+
image:
665+
names:
666+
- ghcr.io/some/base-image:latest
667+
```
668+
669+
#### Tekton Pipeline
670+
671+
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:
672+
673+
```yaml
674+
# [...]
675+
spec:
676+
trigger:
677+
when:
678+
- name: watching over for the Tekton Pipeline
679+
type: Pipeline
680+
objectRef:
681+
status:
682+
- Succeeded
683+
selector:
684+
label: value
685+
```
686+
687+
While the next snippet uses the object name for identification:
688+
689+
```yaml
690+
# [...]
691+
spec:
692+
trigger:
693+
when:
694+
- name: watching over for the Tekton Pipeline
695+
type: Pipeline
696+
objectRef:
697+
status:
698+
- Succeeded
699+
name: tekton-pipeline-name
700+
```
701+
605702
### Sources
606703

607704
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)