From 3ed31d4bcd66d3d18c6b011f79ce43311ac3a7b5 Mon Sep 17 00:00:00 2001 From: James Pace Date: Wed, 15 Feb 2023 23:38:12 -0500 Subject: [PATCH] Add custom multibranch pipeline runner. --- deployments/test-branch-pipeline.yaml | 41 +++++++++++++++++++++++++++ pipelines/test-report-pipeline.yaml | 9 ++++-- tasks/j7s-git-clone-hash.yaml | 23 +++++++++++++++ triggers/test-trigger.yaml | 12 ++++---- 4 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 deployments/test-branch-pipeline.yaml create mode 100644 tasks/j7s-git-clone-hash.yaml diff --git a/deployments/test-branch-pipeline.yaml b/deployments/test-branch-pipeline.yaml new file mode 100644 index 0000000..9e14fa4 --- /dev/null +++ b/deployments/test-branch-pipeline.yaml @@ -0,0 +1,41 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-branch-pipeline-deployment + namespace: j7s-ci + labels: + app: test-branch-pipeline +spec: + replicas: 1 + selector: + matchLabels: + app: test-branch-pipeline + template: + metadata: + labels: + app: test-branch-pipeline + spec: + volumes: + - name: ssh-volume + secret: + secretName: git-credentials + containers: + - name: branch-pipeline + image: 192.168.1.149:8443/j7s_branch_trigger:0.2 + command: ["/bin/bash", "-c"] + volumeMounts: + - mountPath: /ssh-volume + name: ssh-volume + env: + - name: J7S_REPO + value: "ssh://git.jpace121.net:2222/tests/job-test" + - name: J7S_URL + value: http://el-test-pipeline-listener.j7s-ci.svc.cluster.local:8080 + args: + - | + cp -r /ssh-volume ~/.ssh + chmod 700 ~/.ssh + chmod -R 400 ~/.ssh/* + + j7s_branch_trigger \ No newline at end of file diff --git a/pipelines/test-report-pipeline.yaml b/pipelines/test-report-pipeline.yaml index 0da680c..1247d89 100644 --- a/pipelines/test-report-pipeline.yaml +++ b/pipelines/test-report-pipeline.yaml @@ -12,6 +12,9 @@ spec: description: Shared data. - name: git-credentials description: tekton git credentials + params: + - name: hash + default: HEAD tasks: - name: fetch-repo workspaces: @@ -22,10 +25,10 @@ spec: params: - name: url value: ssh://git.jpace121.net:2222/tests/job-test - - name: branch - value: master + - name: hash + value: $(params.hash) taskRef: - name: j7s-git-clone + name: j7s-git-clone-hash - name: cat-readme runAfter: ["fetch-repo"] workspaces: diff --git a/tasks/j7s-git-clone-hash.yaml b/tasks/j7s-git-clone-hash.yaml new file mode 100644 index 0000000..b2521f6 --- /dev/null +++ b/tasks/j7s-git-clone-hash.yaml @@ -0,0 +1,23 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: j7s-git-clone-hash + namespace: j7s-ci +spec: + workspaces: + - name: output + - name: ssh-directory + params: + - name: url + - name: hash + steps: + - image: 192.168.1.149:8443/gitssh:latest + script: | + set -x + cp -r $(workspaces.ssh-directory.path) ~/.ssh + chmod 700 ~/.ssh + chmod -R 400 ~/.ssh/* + + git clone $(params.url) $(workspaces.output.path) + cd $(workspaces.output.path) + git checkout $(params.hash) \ No newline at end of file diff --git a/triggers/test-trigger.yaml b/triggers/test-trigger.yaml index 856d4fc..cce8e82 100644 --- a/triggers/test-trigger.yaml +++ b/triggers/test-trigger.yaml @@ -23,8 +23,8 @@ metadata: namespace: j7s-ci spec: params: - - name: pr-id - value: $(body.pr-id) + - name: hash + value: $(body.hash) --- apiVersion: triggers.tekton.dev/v1beta1 kind: TriggerTemplate @@ -33,7 +33,7 @@ metadata: namespace: j7s-ci spec: params: - - name: pr-id + - name: hash resourcetemplates: - apiVersion: tekton.dev/v1beta1 kind: PipelineRun @@ -41,10 +41,10 @@ spec: generateName: test-pipeline- spec: pipelineRef: - name: test-pipeline + name: test-report-pipeline params: - - name: pr-id - value: "$(tt.params.pr-id)" + - name: hash + value: "$(tt.params.hash)" workspaces: - name: shared-data volumeClaimTemplate: