Skip to content

Commit

Permalink
feat: Add Tekton config to support for BitBucket Cloud (#311)
Browse files Browse the repository at this point in the history
Create Triggers, TriggerTemplates, and Bindings

Signed-off-by: Sergiy Kulanov <[email protected]>
  • Loading branch information
SergK committed Oct 2, 2024
1 parent b86e9da commit 2e11c2b
Show file tree
Hide file tree
Showing 16 changed files with 447 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/pipelines-library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Follows [Tekton Interceptor](https://tekton.dev/vault/triggers-main/clusterinter
| global.dockerRegistry.type | string | `"ecr"` | Define Image Registry that will to be used in Pipelines. Can be ecr (default), harbor, dockerhub |
| global.dockerRegistry.url | string | `"<AWS_ACCOUNT_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com/<registry_space>"` | Docker Registry endpoint. In dockerhub case the URL must be specified in accordance with the Kaniko name convention (docker.io/<registry_space>) |
| global.gerritHost | string | `"gerrit"` | Gerrit Host URL, must be specified if gerrit is enabled |
| global.gitProviders | list | `["github","gitlab","gerrit"]` | Deploy Kubernetes Resources for the specific Git Provider. Can be gerrit, gitlab, github (default) |
| global.gitProviders | list | `["bitbucket","gerrit","github","gitlab"]` | Deploy Kubernetes Resources for the specific Git Provider. Can be gerrit, gitlab, github (default) |
| global.platform | string | `"kubernetes"` | platform type that can be "kubernetes" or "openshift" |
| grafana.dashboards.labelKey | string | `"grafana_dashboard"` | |
| grafana.dashboards.labelValue | string | `"1"` | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ spec:
icon: "PHN2ZyB3aWR0aD0iOTgiIGhlaWdodD0iOTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00OC44NTQgMEMyMS44MzkgMCAwIDIyIDAgNDkuMjE3YzAgMjEuNzU2IDEzLjk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jMuNTkgICAgaC05NS44MzFsLTI1Ljg5NS0xMzUuNDU2aDE0NC45NDVMMzA0LjM3NSwzMjMuNTlMMzA0LjM3NSwzMjMuNTl6IiBzdHlsZT0iZmlsbDojMjY4NEZGOyIvPjwvZz48L2c+PGcgaWQ9IkxheWVyXzEiLz48L3N2Zz4="
{{- else if eq $server.gitProvider "gerrit" }}
icon: "PHN2ZyB3aWR0aD0iNTIiIGhlaWdodD0iNTIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+DQo8cmVjdCByeT0iNCIgcng9IjQiIGhlaWdodD0iNDAiIHdpZHRoPSI0MCIgeT0iMCIgeD0iMCIgZmlsbD0iI2ZmYWFhYSIvPg0KPHJlY3Qgcnk9IjQiIHJ4PSI0IiBoZWlnaHQ9IjQwIiB3aWR0aD0iNDAiIHk9IjEyIiB4PSIxMiIgZmlsbD0iI2FhZmZhYSIvPg0KPHBhdGggZD0ibTE4LDIybDEyLDBsMCw0bC0xMiwwbDAsLTR6IiBmaWxsPSIjZmYwMDAwIi8+DQo8cGF0aCBkPSJtMzQsMjJsMTIsMGwwLDRsLTEyLDBsMCwtNHoiIGZpbGw9IiNmZjAwMDAiLz4NCjxwYXRoIGQ9Im0xOCwzNmw0LDBsMCwtNGw0LDBsMCw0bDQsMGwwLDRsLTQsMGwwLDRsLTQsMGwwLC00bC00LDBsMCwtNHoiIGZpbGw9IiMwMDgwMDAiLz4NCjxwYXRoIGQ9Im0zNCwzNmw0LDBsMCwtNGw0LDBsMCw0bDQsMGwwLDRsLTQsMGwwLDRsLTQsMGwwLC00bC00LDBsMCwtNHoiIGZpbGw9IiMwMDgwMDAiLz4NCjwvc3ZnPg=="
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{ if has "bitbucket" .Values.global.gitProviders }}
apiVersion: triggers.tekton.dev/v1beta1
kind: Trigger
metadata:
name: bitbucket-build
labels:
{{- include "edp-tekton.labels" . | nindent 4 }}
spec:
interceptors:
- ref:
kind: ClusterInterceptor
name: "bitbucket"
params:
- name: "secretRef"
value:
secretName: ci-bitbucket
secretKey: secretString
- name: "eventTypes"
value:
- pullrequest:fulfilled
- ref:
name: "edp"
kind: NamespacedInterceptor
bindings:
- ref: bitbucket-binding-build
template:
ref: bitbucket-build-template
{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{ if has "bitbucket" .Values.global.gitProviders }}
apiVersion: triggers.tekton.dev/v1beta1
kind: Trigger
metadata:
name: bitbucket-review
labels:
{{- include "edp-tekton.labels" . | nindent 4 }}
spec:
interceptors:
- ref:
kind: ClusterInterceptor
name: "bitbucket"
params:
- name: "secretRef"
value:
secretName: ci-bitbucket
secretKey: secretString
- name: "eventTypes"
value:
- pullrequest:created
- pullrequest:comment_created
- pullrequest:updated
- ref:
kind: NamespacedInterceptor
name: "edp"
bindings:
- ref: bitbucket-binding-review
template:
ref: bitbucket-review-template
{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{ if has "bitbucket" .Values.global.gitProviders }}
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerBinding
metadata:
name: bitbucket-binding-build
labels:
{{- include "edp-tekton.labels" . | nindent 4 }}
spec:
params:
- name: gitrevision
value: $(body.object_attributes.target_branch)
- name: gitrepositoryurl
value: $(body.project.git_ssh_url)
- name: gitrepositoryname
value: $(body.project.name)
- name: codebase
value: "$(extensions.codebase)"
- name: codebasebranch
value: "$(extensions.codebasebranch)"
- name: changeNumber
value: "$(extensions.pullRequest.changeNumber)"
# commitMessage is used for 'push-to-jira' Task
- name: commitMessage
value: "$(body.object_attributes.title)"
# commitMessagePattern is used for 'commit-validate' Tasks
- name: commitMessagePattern
value: "$(extensions.spec.commitMessagePattern)"
# jiraIssueMetadataPayload is used for 'push-to-jira' Task
- name: jiraIssueMetadataPayload
value: "$(extensions.spec.jiraIssueMetadataPayload)"
# ticketNamePattern is used for 'push-to-jira' Task
- name: ticketNamePattern
value: "$(extensions.spec.ticketNamePattern)"
# jiraServer is used for 'push-to-jira' Task
- name: jiraServer
value: "$(extensions.spec.jiraServer)"
# get the pipeline name from the codebasebranch spec
- name: pipelineName
value: $(extensions.pipelines.build)
{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{ if has "bitbucket" .Values.global.gitProviders }}
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerBinding
metadata:
name: bitbucket-binding-review
labels:
{{- include "edp-tekton.labels" . | nindent 4 }}
spec:
params:
- name: gitrevision
value: "$(extensions.pullRequest.headSha)"
- name: gitrepositoryurl
value: "$(body.repository.links.html.href)"
- name: gitrepositoryname
value: "$(body.repository.name)"
- name: gitfullrepositoryname
value: "$(body.repository.full_name)"
- name: targetBranch
value: "$(extensions.targetBranch)"
- name: changeNumber
value: "$(extensions.pullRequest.changeNumber)"
- name: commitMessagePattern
value: "$(extensions.spec.commitMessagePattern)"
- name: commitMessage
value: "$(extensions.pullRequest.lastCommitMessage)"
- name: codebase
value: "$(extensions.codebase)"
- name: codebasebranch
value: "$(extensions.codebasebranch)"
# get the pipeline name from the codebasebranch spec
- name: pipelineName
value: $(extensions.pipelines.review)
{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{{ if has "bitbucket" .Values.global.gitProviders }}
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: bitbucket-build-template
labels:
{{- include "edp-tekton.labels" . | nindent 4 }}
spec:
params:
- name: gitrevision
- name: gitrepositoryurl
- name: gitrepositoryname
- name: codebase
description: Codebase name used in pipeline
- name: codebasebranch
description: Codebasebranch name used in pipeline
- name: ticketNamePattern
description: Ticket name pattern
- name: commitMessagePattern
description: Commit message pattern to run commit-validate task
- name: commitMessage
description: Commit message
- name: changeNumber
description: Change number from Merge Request
- name: jiraIssueMetadataPayload
description: Jira issue payload
- name: jiraServer
description: Jira server name
- name: pipelineName
description: Pipeline to trigger. Populated by edp interceptor from codebasebranch spec
resourcetemplates:
- apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
generateName: $(tt.params.codebasebranch)-build-
labels:
# used by UI to sort pipelines for codebasebranches
app.edp.epam.com/codebasebranch: $(tt.params.codebasebranch)
app.edp.epam.com/codebase: $(tt.params.codebase)
app.edp.epam.com/pipelinetype: build
annotations:
argocd.argoproj.io/compare-options: IgnoreExtraneous
spec:
taskRunTemplate:
serviceAccountName: tekton
pipelineRef:
name: $(tt.params.pipelineName)
params:
- name: git-source-url
value: $(tt.params.gitrepositoryurl)
- name: git-source-revision
value: $(tt.params.gitrevision)
- name: CODEBASE_NAME
value: $(tt.params.codebase)
- name: CODEBASEBRANCH_NAME
value: $(tt.params.codebasebranch)
- name: changeNumber
value: $(tt.params.changeNumber)
- name: TICKET_NAME_PATTERN
value: $(tt.params.ticketNamePattern)
- name: COMMIT_MESSAGE_PATTERN
value: $(tt.params.commitMessagePattern)
- name: COMMIT_MESSAGE
value: $(tt.params.commitMessage)
- name: JIRA_ISSUE_METADATA_PAYLOAD
value: $(tt.params.jiraIssueMetadataPayload)
- name: JIRA_SERVER
value: $(tt.params.jiraServer)
workspaces:
- name: shared-workspace
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.tekton.workspaceSize }}
subPath: codebase
- name: ssh-creds
secret:
secretName: ci-bitbucket
{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{{ if has "bitbucket" .Values.global.gitProviders }}
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: bitbucket-review-template
labels:
{{- include "edp-tekton.labels" . | nindent 4 }}
spec:
params:
- name: gitrevision
- name: gitrepositoryurl
- name: gitrepositoryname
- name: gitfullrepositoryname
description: Full Repo name. Used in "bitbucket-set-status" step as REPO_PATH_ONLY
- name: targetBranch
description: Target branch of Merge Request
- name: changeNumber
description: Change number from Merge Request
- name: codebase
description: Codebase name used in pipeline
- name: codebasebranch
description: Codebasebranch name used in pipeline
- name: commitMessagePattern
description: Commit message pattern to run commit-validate task
- name: commitMessage
description: Commit message
- name: pipelineName
description: Pipeline to trigger. Populated by edp interceptor from codebasebranch spec
resourcetemplates:
- apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
generateName: $(tt.params.codebasebranch)-review-
labels:
# used by UI to sort pipelines for codebasebranches
app.edp.epam.com/codebasebranch: $(tt.params.codebasebranch)
app.edp.epam.com/codebase: $(tt.params.codebase)
app.edp.epam.com/pipelinetype: review
annotations:
argocd.argoproj.io/compare-options: IgnoreExtraneous
spec:
taskRunTemplate:
serviceAccountName: tekton
pipelineRef:
name: $(tt.params.pipelineName)
params:
- name: git-source-url
value: $(tt.params.gitrepositoryurl)
- name: git-source-revision
value: $(tt.params.gitrevision)
- name: CODEBASE_NAME
value: $(tt.params.codebase)
- name: CODEBASEBRANCH_NAME
value: $(tt.params.codebasebranch)
- name: targetBranch
value: $(tt.params.targetBranch)
- name: changeNumber
value: $(tt.params.changeNumber)
- name: gitfullrepositoryname
value: $(tt.params.gitfullrepositoryname)
- name: COMMIT_MESSAGE_PATTERN
value: $(tt.params.commitMessagePattern)
- name: COMMIT_MESSAGE
value: $(tt.params.commitMessage)
workspaces:
- name: shared-workspace
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.tekton.workspaceSize }}
subPath: codebase
- name: ssh-creds
secret:
secretName: ci-bitbucket
{{ end }}
3 changes: 2 additions & 1 deletion charts/pipelines-library/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ global:
# Pipelines, EventListener, Tasks, etc.
# -- Deploy Kubernetes Resources for the specific Git Provider. Can be gerrit, gitlab, github (default)
gitProviders:
- bitbucket
- gerrit
- github
- gitlab
- gerrit

# -- Gerrit SSH node port, must be specified if gerrit is enabled
# gerritSSHPort: "30003"
Expand Down
44 changes: 44 additions & 0 deletions tests/e2e/bitbucket/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# We need to ensure that the following deployments are ready before we start testing
apiVersion: apps/v1
kind: Deployment
metadata:
name: cert-manager
namespace: cert-manager
status:
readyReplicas: 1

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tekton-pipelines-controller
namespace: tekton-pipelines
status:
readyReplicas: 1

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tekton-pipelines-webhook
namespace: tekton-pipelines
status:
readyReplicas: 1

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tekton-triggers-controller
namespace: tekton-pipelines
status:
readyReplicas: 1

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tekton-triggers-webhook
namespace: tekton-pipelines
status:
readyReplicas: 1
23 changes: 23 additions & 0 deletions tests/e2e/bitbucket/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: check-readiness
status:
conditions:
- reason: Succeeded
status: 'True'
type: Succeeded
pipelineSpec:
tasks:
- name: check
taskSpec:
metadata:
labels:
app: example
steps:
- computeResources: {}
image: alpine:3.18.6
name: echo
script: |
#!/usr/bin/env sh
echo "I'm ok!"
Loading

0 comments on commit 2e11c2b

Please sign in to comment.