-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace gitlab-eventlistener with a working example
I moved this to a separate folder so that it was easy to add the sample payload as well as instructions for trying it out locally. Signed-off-by: Dibyo Mukherjee <dibyo@google.com>
- Loading branch information
Showing
5 changed files
with
183 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
examples/eventlisteners/gitlab-eventlistener-interceptor.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
## GitLab Push EventListener | ||
|
||
Creates an EventListener that listens for Gitlab webhook events. | ||
|
||
### Try it out locally: | ||
|
||
1. Create the service account: | ||
|
||
```shell script | ||
kubectl apply -f examples/role-resources/triggerbinding-roles | ||
kubectl apply -f examples/role-resources/ | ||
``` | ||
|
||
1. Create the Gitlab EventListener: | ||
|
||
```shell script | ||
kubectl apply -f examples/gitlab/gitlab-push-listener.yaml | ||
``` | ||
|
||
1. Port forward: | ||
|
||
```shell script | ||
kubectl port-forward \ | ||
"$(kubectl get pod --selector=eventlistener=gitlab-listener -oname)" \ | ||
8080 | ||
``` | ||
|
||
**Note**: Instead of port forwarding, you can set the | ||
[`serviceType`](https://github.com/tektoncd/triggers/blob/master/docs/eventlisteners.md#serviceType) | ||
to `LoadBalancer` to expose the EventListener with a public IP. | ||
|
||
1. Test by sending the sample payload. | ||
|
||
```shell script | ||
curl -v \ | ||
-H 'X-GitLab-Token: abcde' \ | ||
-H 'X-Gitlab-Event: Push Hook' \ | ||
-H 'Content-Type: application/json' \ | ||
--data-binary "@examples/gitlab/gitlab-push-event.json" \ | ||
http://localhost:8080 | ||
``` | ||
|
||
The response status code should be `201 Created` | ||
|
||
1. You should see a new TaskRun that got created: | ||
|
||
```shell script | ||
kubectl get taskruns | grep gitlab-run- | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"object_kind": "push", | ||
"event_name": "push", | ||
"before": "1a1736ec3d7b03349b31218a2f2c572c7c7206d6", | ||
"after": "1a1736ec3d7b03349b31218a2f2c572c7c7206d6", | ||
"ref": "refs/heads/master", | ||
"checkout_sha": "1a1736ec3d7b03349b31218a2f2c572c7c7206d6", | ||
"message": null, | ||
"user_id": 111448, | ||
"user_name": "Dibyo Mukherjee", | ||
"user_username": "dibyom", | ||
"user_email": "", | ||
"user_avatar": "https://secure.gravatar.com/avatar/1d56773f447d86b8ffa33efb7a5d0cb5?s=80&d=identicon", | ||
"project_id": 16507326, | ||
"project": { | ||
"id": 16507326, | ||
"name": "triggers", | ||
"description": "", | ||
"web_url": "https://gitlab.com/dibyom/triggers", | ||
"avatar_url": null, | ||
"git_ssh_url": "git@gitlab.com:dibyom/triggers.git", | ||
"git_http_url": "https://gitlab.com/dibyom/triggers.git", | ||
"namespace": "Dibyo Mukherjee", | ||
"visibility_level": 20, | ||
"path_with_namespace": "dibyom/triggers", | ||
"default_branch": "master", | ||
"ci_config_path": null, | ||
"homepage": "https://gitlab.com/dibyom/triggers", | ||
"url": "git@gitlab.com:dibyom/triggers.git", | ||
"ssh_url": "git@gitlab.com:dibyom/triggers.git", | ||
"http_url": "https://gitlab.com/dibyom/triggers.git" | ||
}, | ||
"commits": [ | ||
{ | ||
"id": "1a1736ec3d7b03349b31218a2f2c572c7c7206d6", | ||
"message": "Add new file", | ||
"timestamp": "2020-01-24T17:05:48+00:00", | ||
"url": "https://gitlab.com/dibyom/triggers/-/commit/1a1736ec3d7b03349b31218a2f2c572c7c7206d6", | ||
"author": { | ||
"name": "Dibyo Mukherjee", | ||
"email": "foo@bar.com" | ||
}, | ||
"added": ["Readme.md"], | ||
"modified": [], | ||
"removed": [] | ||
} | ||
], | ||
"total_commits_count": 1, | ||
"push_options": {}, | ||
"repository": { | ||
"name": "triggers", | ||
"url": "git@gitlab.com:dibyom/triggers.git", | ||
"description": "", | ||
"homepage": "https://gitlab.com/dibyom/triggers", | ||
"git_http_url": "https://gitlab.com/dibyom/triggers.git", | ||
"git_ssh_url": "git@gitlab.com:dibyom/triggers.git", | ||
"visibility_level": 20 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: TriggerTemplate | ||
metadata: | ||
name: gitlab-echo-template | ||
spec: | ||
params: | ||
- name: gitrevision | ||
- name: gitrepositoryurl | ||
resourcetemplates: | ||
- apiVersion: tekton.dev/v1alpha1 | ||
kind: TaskRun | ||
metadata: | ||
generateName: gitlab-run- | ||
spec: | ||
taskSpec: | ||
inputs: | ||
resources: | ||
- name: source | ||
type: git | ||
steps: | ||
- image: ubuntu | ||
script: | | ||
#! /bin/bash | ||
ls -al $(inputs.resources.source.path) | ||
inputs: | ||
resources: | ||
- name: source | ||
resourceSpec: | ||
type: git | ||
params: | ||
- name: revision | ||
value: $(params.gitrevision) | ||
- name: url | ||
value: $(params.gitrepositoryurl) | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: TriggerBinding | ||
metadata: | ||
name: gitlab-push-binding | ||
spec: | ||
params: | ||
- name: gitrevision | ||
value: $(body.checkout_sha) | ||
- name: gitrepositoryurl | ||
value: $(body.repository.git_http_url) | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: gitlab-secret | ||
type: Opaque | ||
stringData: | ||
gitlabToken: abcde | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: EventListener | ||
metadata: | ||
name: gitlab-listener | ||
spec: | ||
# from examples/role-resources/servicaccount.yaml | ||
serviceAccountName: tekton-triggers-example-sa | ||
triggers: | ||
- name: gitlab-push-events-trigger | ||
interceptors: | ||
- gitlab: | ||
secretRef: | ||
secretName: gitlab-secret | ||
secretKey: gitlabToken | ||
eventTypes: | ||
- Push Hook # Only push events | ||
bindings: | ||
- name: gitlab-push-binding | ||
template: | ||
name: gitlab-echo-template |