-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BitBucket Interceptor with examples and README
- Loading branch information
1 parent
d030a5b
commit dd1aff6
Showing
20 changed files
with
748 additions
and
53 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
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,45 @@ | ||
## Bitbucket EventListener | ||
|
||
Creates an EventListener that listens for Bitbucket webhook events. | ||
|
||
### Try it out locally: | ||
|
||
1. To create the Bitbucket trigger and all related resources, run: | ||
|
||
```bash | ||
kubectl apply -f examples/bitbucket/ | ||
``` | ||
|
||
1. Port forward: | ||
|
||
```bash | ||
kubectl port-forward \ | ||
"$(kubectl get pod --selector=eventlistener=bitbucket-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. | ||
|
||
```bash | ||
curl -v \ | ||
-H 'X-Event-Key: repo:refs_changed' \ | ||
-H 'X-Hub-Signature: sha1=c401e56873be567c1403d8504763760a39236c51' \ | ||
-d '{"repository": {"links": {"clone": [{"href": "ssh://git@localhost:7999/~test/helloworld.git", "name": "ssh"}, {"href": "http://localhost:7990/scm/~test/helloworld.git", "name": "http"}]}}, "changes": [{"ref": {"displayId": "master"}}]}' \ | ||
http://localhost:8080 | ||
``` | ||
|
||
The response status code should be `201 Created` | ||
|
||
[`HMAC`](https://www.freeformatter.com/hmac-generator.html) tool used to create X-Hub-Signature. | ||
|
||
In [`HMAC`](https://www.freeformatter.com/hmac-generator.html) `string` is the *body payload* and `secretKey` is the *given secretToken*. | ||
|
||
1. You should see a new TaskRun that got created: | ||
|
||
```bash | ||
kubectl get taskruns | grep bitbucket-run- | ||
``` |
20 changes: 20 additions & 0 deletions
20
examples/bitbucket/bitbucket-eventlistener-interceptor.yaml
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,20 @@ | ||
--- | ||
apiVersion: triggers.tekton.dev/v1alpha1 | ||
kind: EventListener | ||
metadata: | ||
name: bitbucket-listener | ||
spec: | ||
serviceAccountName: tekton-triggers-bitbucket-sa | ||
triggers: | ||
- name: bitbucket-triggers | ||
interceptors: | ||
- bitbucket: | ||
secretRef: | ||
secretName: bitbucket-secret | ||
secretKey: secretToken | ||
eventTypes: | ||
- repo:refs_changed | ||
bindings: | ||
- name: bitbucket-binding | ||
template: | ||
name: bitbucket-template |
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,36 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: tekton-triggers-bitbucket-sa | ||
secrets: | ||
- name: bitbucket-secret | ||
--- | ||
kind: Role | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: tekton-triggers-bitbucket-minimal | ||
rules: | ||
# Permissions for every EventListener deployment to function | ||
- apiGroups: ["triggers.tekton.dev"] | ||
resources: ["eventlisteners", "triggerbindings", "triggertemplates"] | ||
verbs: ["get"] | ||
- apiGroups: [""] | ||
# secrets are only needed for Github/Gitlab interceptors, serviceaccounts only for per trigger authorization | ||
resources: ["configmaps", "secrets", "serviceaccounts"] | ||
verbs: ["get", "list", "watch"] | ||
# Permissions to create resources in associated TriggerTemplates | ||
- apiGroups: ["tekton.dev"] | ||
resources: ["pipelineruns", "pipelineresources", "taskruns"] | ||
verbs: ["create"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: tekton-triggers-bitbucket-binding | ||
subjects: | ||
- kind: ServiceAccount | ||
name: tekton-triggers-bitbucket-sa | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: tekton-triggers-bitbucket-minimal |
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,7 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: bitbucket-secret | ||
type: Opaque | ||
stringData: | ||
secretToken: "1234567" |
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,11 @@ | ||
--- | ||
apiVersion: triggers.tekton.dev/v1alpha1 | ||
kind: TriggerBinding | ||
metadata: | ||
name: bitbucket-binding | ||
spec: | ||
params: | ||
- name: gitrevision | ||
value: $(body.changes[0].ref.displayId) | ||
- name: gitrepositoryurl | ||
value: $(body.repository.links.clone[1].href) |
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,35 @@ | ||
--- | ||
apiVersion: triggers.tekton.dev/v1alpha1 | ||
kind: TriggerTemplate | ||
metadata: | ||
name: bitbucket-template | ||
spec: | ||
params: | ||
- name: gitrevision | ||
- name: gitrepositoryurl | ||
resourcetemplates: | ||
- apiVersion: tekton.dev/v1alpha1 | ||
kind: TaskRun | ||
metadata: | ||
generateName: bitbucket-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) |
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.