diff --git a/deployments/hook-bot.yaml b/deployments/hook-bot.yaml new file mode 100644 index 0000000..234e105 --- /dev/null +++ b/deployments/hook-bot.yaml @@ -0,0 +1,58 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: tekton-hook-bot-deployment + labels: + app: tekton-hook-bot +spec: + replicas: 1 + selector: + matchLabels: + app: tekton-hook-bot + template: + metadata: + labels: + app: tekton-hook-bot + spec: + containers: + - name: tekton-hook-bot + image: 192.168.1.128:8443/tekton-hooks-bot:0.3 + env: + - name: LISTEN_ADDR + value: 0.0.0.0:3000 + - name: SERVICE_ADDR + value: el-test-listener:8080 + ports: + - containerPort: 3000 + name: service-port +--- +apiVersion: v1 +kind: Service +metadata: + name: hook-bot-service +spec: + selector: + app: tekton-hook-bot + ports: + - protocol: TCP + targetPort: 3000 + port: 3000 + name: service-port +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: hook-bot-ingress +spec: + rules: + - host: tekton.internal.jpace121.net + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: hook-bot-service + port: + number: 3000 \ No newline at end of file diff --git a/pipelines/git-pipeline.yaml b/pipelines/git-pipeline.yaml index 2336626..972cf2d 100644 --- a/pipelines/git-pipeline.yaml +++ b/pipelines/git-pipeline.yaml @@ -8,6 +8,13 @@ spec: - name: repo-url type: string description: The git repository URL to clone from. + - name: commit + type: string + description: The git hash to checkout. + - name: use-gerrit + type: string + description: Should we report back to gerrit? + default: "false" workspaces: - name: shared-data description: Shared data. @@ -23,9 +30,10 @@ spec: params: - name: url value: $(params.repo-url) + - name: commit + value: $(params.commit) taskRef: name: j7s-git-clone - - name: cat-readme runAfter: ["fetch-repo"] workspaces: @@ -39,3 +47,41 @@ spec: script: | set -x cat $(workspaces.source.path)/README + + finally: + - name: notify-gerrit-success + when: + - input: $(tasks.status) + operator: notin + values: ["Failed"] + - input: $(params.use-gerrit) + operator: in + values: ["true"] + params: + - name: commit + value: $(params.commit) + - name: build-id + value: $(context.pipelineRun.name) + workspaces: + - name: ssh-directory + workspace: git-credentials + taskRef: + name: j7s-gerrit-success + - name: notify-gerrit-failed + when: + - input: $(tasks.status) + operator: in + values: ["Failed"] + - input: $(params.use-gerrit) + operator: in + values: ["true"] + params: + - name: commit + value: $(params.commit) + - name: build-id + value: $(context.pipelineRun.name) + workspaces: + - name: ssh-directory + workspace: git-credentials + taskRef: + name: j7s-gerrit-fail \ No newline at end of file diff --git a/runs/git-run.yaml b/runs/git-run.yaml index 92f2a78..bc0f206 100644 --- a/runs/git-run.yaml +++ b/runs/git-run.yaml @@ -1,7 +1,7 @@ apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: - name: with-good-layout + name: with-good-layout-9 spec: pipelineRef: name: git-pipeline @@ -20,3 +20,7 @@ spec: params: - name: repo-url value: ssh://git@git.jpace121.net:2222/jimmy/tekton-test.git + - name: commit + value: master + - name: use-gerrit + value: false diff --git a/tasks/j7s-gerrit-fail.yaml b/tasks/j7s-gerrit-fail.yaml new file mode 100644 index 0000000..c7c4e6c --- /dev/null +++ b/tasks/j7s-gerrit-fail.yaml @@ -0,0 +1,22 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: j7s-gerrit-fail +spec: + workspaces: + - name: ssh-directory + params: + - name: commit + - name: build-id + steps: + - image: 192.168.1.128:8443/gitssh:latest + script: | + #!/usr/bin/env bash + set -ex + cp -r $(workspaces.ssh-directory.path) ~/.ssh + chmod 700 ~/.ssh + chmod -R 400 ~/.ssh/* + ssh -p 29418 tekton@gerrit.internal.jpace121.net gerrit review \ + -m '"Build failed. ID: $(params.build-id)"' \ + --verified -1 \ + $(params.commit) \ No newline at end of file diff --git a/tasks/j7s-gerrit-success.yaml b/tasks/j7s-gerrit-success.yaml new file mode 100644 index 0000000..79681cd --- /dev/null +++ b/tasks/j7s-gerrit-success.yaml @@ -0,0 +1,22 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: j7s-gerrit-success +spec: + workspaces: + - name: ssh-directory + params: + - name: commit + - name: build-id + steps: + - image: 192.168.1.128:8443/gitssh:latest + script: | + #!/usr/bin/env bash + set -ex + cp -r $(workspaces.ssh-directory.path) ~/.ssh + chmod 700 ~/.ssh + chmod -R 400 ~/.ssh/* + ssh -p 29418 tekton@gerrit.internal.jpace121.net gerrit review \ + -m '"Build success. ID: $(params.build-id)"' \ + --verified +1 \ + $(params.commit) \ No newline at end of file diff --git a/tasks/j7s-git-clone.yaml b/tasks/j7s-git-clone.yaml index c6c5775..786d64d 100644 --- a/tasks/j7s-git-clone.yaml +++ b/tasks/j7s-git-clone.yaml @@ -8,6 +8,7 @@ spec: - name: ssh-directory params: - name: url + - name: commit steps: - image: 192.168.1.128:8443/gitssh:latest script: | @@ -15,4 +16,6 @@ spec: cp -r $(workspaces.ssh-directory.path) ~/.ssh chmod 700 ~/.ssh chmod -R 400 ~/.ssh/* - git clone $(params.url) $(workspaces.output.path) \ No newline at end of file + git clone $(params.url) $(workspaces.output.path) + cd $(workspaces.output.path) + git checkout -f $(params.commit) \ No newline at end of file