mirror of
https://github.com/bvanroll/stage-infra.git
synced 2025-08-29 12:02:48 +00:00
multiple listeners. TODO create different pipelines for each listener
This commit is contained in:
97
Tekton/tasks/github-set-status.yaml
Normal file
97
Tekton/tasks/github-set-status.yaml
Normal file
@@ -0,0 +1,97 @@
|
||||
---
|
||||
apiVersion: tekton.dev/v1alpha1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: github-set-status
|
||||
namespace: tekton-pipeline-1
|
||||
description: |
|
||||
This task will set the CI as running and add a link to the openshift console
|
||||
viewer url.
|
||||
spec:
|
||||
params:
|
||||
- name: GITHUB_HOST_URL
|
||||
description: |
|
||||
The GitHub host, adjust this if you run a GitHub enteprise.
|
||||
default: "api.github.com"
|
||||
type: string
|
||||
|
||||
- name: API_PATH_PREFIX
|
||||
description: |
|
||||
The API path prefix, GitHub Enterprise has a prefix e.g. /api/v3
|
||||
default: ""
|
||||
type: string
|
||||
|
||||
- name: REPO_FULL_NAME
|
||||
description: |
|
||||
The GitHub repository full name, i.e: tektoncd/catalog
|
||||
type: string
|
||||
|
||||
- name: SHA
|
||||
description: |
|
||||
Commit SHA to set the status for.
|
||||
type: string
|
||||
|
||||
- name: TARGET_URL
|
||||
description: |
|
||||
The target URL to associate with this status. This URL will be linked
|
||||
from the GitHub UI to allow users to easily see the source of the
|
||||
status.
|
||||
type: string
|
||||
|
||||
- name: DESCRIPTION
|
||||
description: |
|
||||
A short description of the status.
|
||||
type: string
|
||||
|
||||
- name: CONTEXT
|
||||
description: |
|
||||
The GitHub context, A string label to differentiate this status from
|
||||
the status of other systems. ie: "continuous-integration/tekton"
|
||||
default: "continuous-integration/tekton"
|
||||
type: string
|
||||
|
||||
- name: STATE
|
||||
description: |
|
||||
The state of the status. Can be one of the following `error`,
|
||||
`failure`, `pending`, or `success`.
|
||||
type: string
|
||||
steps:
|
||||
- name: set-status
|
||||
env:
|
||||
- name: GITHUBTOKEN
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: github
|
||||
key: token
|
||||
image: registry.access.redhat.com/ubi8/ubi:latest
|
||||
script: |
|
||||
#!/usr/libexec/platform-python
|
||||
import json
|
||||
import os
|
||||
import http.client
|
||||
status_url = "$(params.API_PATH_PREFIX)" + "/repos/$(params.REPO_FULL_NAME)/" + \
|
||||
"statuses/$(params.SHA)"
|
||||
data = {
|
||||
"state": "$(params.STATE)",
|
||||
"target_url": "$(params.TARGET_URL)",
|
||||
"description": "$(params.DESCRIPTION)",
|
||||
"context": "$(params.CONTEXT)"
|
||||
}
|
||||
print("Sending this data to GitHub: ")
|
||||
print(data)
|
||||
conn = http.client.HTTPSConnection("$(params.GITHUB_HOST_URL)")
|
||||
r = conn.request(
|
||||
"POST",
|
||||
status_url,
|
||||
body=json.dumps(data),
|
||||
headers={
|
||||
"User-Agent": "TektonCD, the peaceful cat",
|
||||
"Authorization": "Bearer " + os.environ["GITHUBTOKEN"],
|
||||
})
|
||||
resp = conn.getresponse()
|
||||
if not str(resp.status).startswith("2"):
|
||||
print("Error: %d" % (resp.status))
|
||||
print(resp.read())
|
||||
else:
|
||||
print("GitHub status '$(params.STATE)' has been set on "
|
||||
"$(params.REPO_FULL_NAME)#$(params.SHA) ")
|
Reference in New Issue
Block a user