chore: added status events
This commit is contained in:
@@ -37,7 +37,25 @@ spec:
|
||||
- name: quayhost
|
||||
description: the base quay server hostname
|
||||
tasks:
|
||||
- name: set-pending-status
|
||||
taskRef:
|
||||
name: gitea-set-status
|
||||
params:
|
||||
- name: statusurl
|
||||
value: https://console-openshift-console.apps.ocp.endofday.com/pipelines/ns/goghvideo-cicd-pipeline/pipeline-runs
|
||||
- name: revision
|
||||
value: $(params.revision)
|
||||
- name: repofullname
|
||||
value: $(params.repofullname)
|
||||
- name: description
|
||||
value: "CI Pipeline"
|
||||
- name: state
|
||||
value: "pending"
|
||||
workspaces:
|
||||
- name: gitauth
|
||||
workspace: gitauth
|
||||
- name: prepare
|
||||
runAfter: ["set-pending-status"]
|
||||
taskRef:
|
||||
name: git-semver
|
||||
params:
|
||||
@@ -303,8 +321,26 @@ spec:
|
||||
workspaces:
|
||||
- name: kubeconfig-dir
|
||||
workspace: dockerconfig
|
||||
- name: promote
|
||||
- name: set-success-status
|
||||
runAfter: ["perform-e2e-test"]
|
||||
taskRef:
|
||||
name: gitea-set-status
|
||||
params:
|
||||
- name: statusurl
|
||||
value: https://console-openshift-console.apps.ocp.endofday.com/pipelines/ns/goghvideo-cicd-pipeline/pipeline-runs
|
||||
- name: revision
|
||||
value: $(params.revision)
|
||||
- name: repofullname
|
||||
value: $(params.repofullname)
|
||||
- name: description
|
||||
value: "CI Pipeline"
|
||||
- name: state
|
||||
value: "success"
|
||||
workspaces:
|
||||
- name: gitauth
|
||||
workspace: gitauth
|
||||
- name: promote
|
||||
runAfter: ["set-success-status"]
|
||||
taskref:
|
||||
name: promote
|
||||
kind: Task
|
||||
|
||||
@@ -8,74 +8,28 @@ spec:
|
||||
This task will set the status of the CI job to the specified value along with a link to the specified target URL where developers can follow the progress of the CI job.
|
||||
The `gitea-set-status` task allows external services to mark Gitea commits with an `error`, `failure`, `pending`, or `success` state, which is then reflected in pull requests involving those commits. Statuses include as well a `description` and a `target_url`, to give the user informations about the CI statuses or a direct link to the full log.
|
||||
params:
|
||||
- description: |
|
||||
The Gitea host, e.g: git.yourcompany.com. Can include port.
|
||||
name: GITEA_HOST_URL
|
||||
- name: githost
|
||||
type: string
|
||||
- default: https
|
||||
description: |
|
||||
If we should connect with HTTP or HTTPS. Use "http" or "https" here.
|
||||
name: GITEA_HTTPS_OR_HTTP
|
||||
- name: quayhost
|
||||
type: string
|
||||
- default: /api/v1
|
||||
description: |
|
||||
The API path prefix of Gitea, default: /api/v1
|
||||
name: API_PATH_PREFIX
|
||||
- name: repofullname
|
||||
type: string
|
||||
- description: |
|
||||
The Gitea repository full name, e.g.: tektoncd/catalog
|
||||
name: REPO_FULL_NAME
|
||||
- name: revision
|
||||
type: string
|
||||
- default: gitea
|
||||
description: |
|
||||
The name of the kubernetes secret that contains the Gitea token, default: gitea
|
||||
name: GITEA_TOKEN_SECRET_NAME
|
||||
- name: statusurl
|
||||
type: string
|
||||
- default: token
|
||||
description: |
|
||||
The key within the kubernetes secret that contains the Gitea token, default: token
|
||||
name: GITEA_TOKEN_SECRET_KEY
|
||||
- name: description
|
||||
type: string
|
||||
- description: |
|
||||
Commit SHA to set the status for.
|
||||
name: SHA
|
||||
- name: context
|
||||
type: string
|
||||
- description: |
|
||||
The target URL to associate with this status. This URL will be linked
|
||||
from the Gitea UI to allow users to easily see the source of the
|
||||
status.
|
||||
name: TARGET_URL
|
||||
type: string
|
||||
- description: |
|
||||
A short description of the status.
|
||||
name: DESCRIPTION
|
||||
type: string
|
||||
- default: continuous-integration/tekton
|
||||
description: |
|
||||
The Gitea context, A string label to differentiate this status from
|
||||
the status of other systems. ie: "continuous-integration/tekton"
|
||||
name: CONTEXT
|
||||
type: string
|
||||
- description: |
|
||||
The state of the status. Can be one of the following `error`,
|
||||
`failure`, `pending`, `warning` or `success`.
|
||||
name: STATE
|
||||
type: string
|
||||
- default: python:3.10.1-alpine3.15@sha256:affe0faa14e7553fc570beec3864e74b5e36f8c19b2bb49ae8ba79c0e9e7236e
|
||||
description: |
|
||||
Image providing the python binary which this task uses.
|
||||
name: IMAGE
|
||||
type: string
|
||||
- default: /usr/bin/env python
|
||||
description: |
|
||||
Python path. Depends on the image.
|
||||
name: SHEBANG
|
||||
default: continuous-integration/tekton
|
||||
- name: state
|
||||
type: string
|
||||
steps:
|
||||
- image: $(params.IMAGE)
|
||||
- image: $(params.quayhost)/goghvideo/python:3-alpine
|
||||
name: set-status
|
||||
script: |
|
||||
#!$(params.SHEBANG)
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""This script will set the CI status on a Gitea commit"""
|
||||
|
||||
@@ -83,26 +37,22 @@ spec:
|
||||
import sys
|
||||
import http.client
|
||||
|
||||
gitea_token = open("/etc/gitea-set-status/$(params.GITEA_TOKEN_SECRET_KEY)", "r").read()
|
||||
gitea_token = open("$(workspaces.gitauth.path)/password", "r").read()
|
||||
|
||||
status_url = "$(params.API_PATH_PREFIX)" + "/repos/$(params.REPO_FULL_NAME)/" + \
|
||||
"statuses/$(params.SHA)"
|
||||
status_url = "/api/v1/repos/$(params.repofullname)/statuses/$(params.revision)"
|
||||
|
||||
data = {
|
||||
"state": "$(params.STATE)",
|
||||
"target_url": "$(params.TARGET_URL)",
|
||||
"description": "$(params.DESCRIPTION)",
|
||||
"context": "$(params.CONTEXT)"
|
||||
"state": "$(params.state)",
|
||||
"target_url": "$(params.statusurl)",
|
||||
"description": "$(params.description)",
|
||||
"context": "$(params.context)"
|
||||
}
|
||||
print("Sending this data to Gitea: ")
|
||||
print(data)
|
||||
|
||||
authHeader = "token " + gitea_token
|
||||
|
||||
if "$(params.GITEA_HTTPS_OR_HTTP)" == "https":
|
||||
conn = http.client.HTTPSConnection("$(params.GITEA_HOST_URL)")
|
||||
else:
|
||||
conn = http.client.HTTPConnection("$(params.GITEA_HOST_URL)")
|
||||
conn = http.client.HTTPSConnection("$(params.githost)")
|
||||
|
||||
conn.request(
|
||||
"POST",
|
||||
@@ -120,12 +70,7 @@ spec:
|
||||
print(resp.read())
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("Gitea status '$(params.STATE)' has been set on "
|
||||
"$(params.REPO_FULL_NAME)#$(params.SHA) ")
|
||||
volumeMounts:
|
||||
- mountPath: /etc/gitea-set-status
|
||||
name: giteatoken
|
||||
volumes:
|
||||
- name: giteatoken
|
||||
secret:
|
||||
secretName: $(params.GITEA_TOKEN_SECRET_NAME)
|
||||
print("Gitea status has been set")
|
||||
workspaces:
|
||||
- name: gitauth
|
||||
|
||||
|
||||
Reference in New Issue
Block a user