mirror of
https://github.com/tektoncd/catalog.git
synced 2024-11-21 05:55:35 +00:00
Add jira-get-ticket-status task
Update jira-get-ticket-status.yaml Add SHA instead of tag named Changed secret name and now have a parameter to specify the value Improve documentation Improve documentation Update api version and minimal pipeline compatible version Fix trailing spaces on python code
This commit is contained in:
parent
957d92a075
commit
96c4ea272d
57
task/jira-get-ticket-status/0.1/README.md
Normal file
57
task/jira-get-ticket-status/0.1/README.md
Normal file
@ -0,0 +1,57 @@
|
||||
# Jira - Get Ticket Status
|
||||
|
||||
This task helps you to get the current status of a Jira ticket.
|
||||
|
||||
## Install the Task
|
||||
|
||||
```
|
||||
kubectl apply -f https://api.hub.tekton.dev/v1/resource/tekton/task/jira-get-ticket-status/0.1/raw
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
* **ticket_id:** Jira Ticket ID.
|
||||
* **ssl_verify:** Verify or not SSL certificates (by default: `true`).
|
||||
* **secret_name:** The name of the secret that have the Jira URL and the Bearer token.
|
||||
|
||||
## Results
|
||||
|
||||
* **ticket_status**: Current Jira Ticket status
|
||||
|
||||
## Platforms
|
||||
|
||||
The Task can be run on `linux/amd64` platform.
|
||||
|
||||
## Usage
|
||||
|
||||
This Task implements a `Secret`to provide the required **Bearer Token** to authenticate with Jira platform. For example:
|
||||
|
||||
```yaml
|
||||
# Complete the fields indicated below
|
||||
kind: Secret
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: jira-config
|
||||
stringData:
|
||||
JIRA_BEARER_TOKEN: #{BEARER_TOKEN}
|
||||
JIRA_URL: #{JIRA_PLATFORM_URL}
|
||||
type: Opaque
|
||||
```
|
||||
|
||||
Then, to use it in a `Pipeline` only reference this Task properly:
|
||||
```yaml
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: Pipeline
|
||||
metadata:
|
||||
name: example-jira-pipeline
|
||||
spec:
|
||||
tasks:
|
||||
- name: verify-jira-ticket-status
|
||||
taskRef:
|
||||
name: jira-get-ticket-status
|
||||
params:
|
||||
- name: ticket_id
|
||||
value: 'KAN-3'
|
||||
- name: secret_name
|
||||
value: jira-config
|
||||
```
|
81
task/jira-get-ticket-status/0.1/jira-get-ticket-status.yaml
Normal file
81
task/jira-get-ticket-status/0.1/jira-get-ticket-status.yaml
Normal file
@ -0,0 +1,81 @@
|
||||
apiVersion: tekton.dev/v1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: jira-get-ticket-status
|
||||
labels:
|
||||
app.kubernetes.io/version: "0.1"
|
||||
annotations:
|
||||
tekton.dev/pipelines.minVersion: "0.56.4"
|
||||
tekton.dev/categories: Automation
|
||||
tekton.dev/tags: jira, get, ticket, status
|
||||
tekton.dev/displayName: "Jira - Get Ticket Status"
|
||||
tekton.dev/platforms: "linux/amd64"
|
||||
spec:
|
||||
description: >-
|
||||
This task helps you to get the current status of a Jira ticket.
|
||||
params:
|
||||
- name: ticket_id
|
||||
description: Jira Ticket ID
|
||||
type: string
|
||||
- name: ssl_verify
|
||||
default: "true"
|
||||
description: Verify or not SSL certificates
|
||||
- name: secret_name
|
||||
description: the name of the secret that have the Jira URL and the Bearer token
|
||||
type: string
|
||||
results:
|
||||
- name: ticket_status
|
||||
description: Jira Ticket status
|
||||
stepTemplate:
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: $(params.secret_name)
|
||||
steps:
|
||||
- name: get-ticket-status
|
||||
image: registry.access.redhat.com/ubi8/python-39@sha256:27e795fd6b1b77de70d1dc73a65e4c790650748a9cfda138fdbd194b3d6eea3d
|
||||
command:
|
||||
- sh
|
||||
- '-c'
|
||||
args:
|
||||
- |
|
||||
pip install requests &>/dev/null
|
||||
python -c "
|
||||
import requests
|
||||
import os
|
||||
|
||||
jira_url = os.getenv('JIRA_URL')
|
||||
ssl_verify = os.getenv('SSL_VERIFY')
|
||||
token = os.getenv('JIRA_BEARER_TOKEN')
|
||||
ticket_id = os.getenv('TICKET_ID')
|
||||
url = str(jira_url) + '/rest/api/2/issue/' + str(ticket_id)
|
||||
print(f'--> Using the URL: {url}')
|
||||
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + str(token)
|
||||
}
|
||||
|
||||
if ssl_verify.lower().strip() == 'true':
|
||||
ssl_verify = True
|
||||
else:
|
||||
ssl_verify = False
|
||||
|
||||
response = requests.get(url, headers=headers, verify=ssl_verify)
|
||||
if response.status_code == 200:
|
||||
print(f'--> The query to ticket {ticket_id} was successful! ')
|
||||
data = response.json()
|
||||
status = data.get('fields', {}).get('status', {}).get('name')
|
||||
print(f'--> The status of ticket {ticket_id} is: {status}')
|
||||
with open('$(results.ticket_status.path)', 'w') as file:
|
||||
file.write(status)
|
||||
else:
|
||||
print(f'Error getting the status of ticket {ticket_id}')
|
||||
print(f'HTTP Code: {response.status_code}')
|
||||
print(response.json())
|
||||
raise Exception('Error getting ticket status')
|
||||
"
|
||||
env:
|
||||
- name: TICKET_ID
|
||||
value: $(params.ticket_id)
|
||||
- name: SSL_VERIFY
|
||||
value: $(params.ssl_verify)
|
Loading…
Reference in New Issue
Block a user