Python Script with below JIRA operations
- Fetch JIRA ticket details using JIRA API.
- Create JIRA ticket using JIRA API
Information to collect before using script.
- Get your organization JIRA URL handy with you.
- Can be retrieved from any JIRA ticket URL, respective URL has FQDN that's the JIRA URL dedicated for your organization.
- Know your JIRA project/space name.
- Login to any of your JIRA tickets.
- From top navigation panel, select projects and check the name associated with the project, project name will be single word without any space.
- Know JIRA field/mandatory fields within your ticket, before you create a ticket via API.
- Will know how to fetch details about it from our python script, get_jita_details method can be used to get details for field
Script has one class and two methods, will know how and when to use one by one.
- JiraHandler ( Class )
- get_jira_details ( Method ) - Can be used to fetch JIRA ticket details.
- create_jira_cr_ticket( Method ) - Can be used to create new JIRA ticket.
Note :
- For simplicity, i have used basic authentication method to authenticate to JIRA servers, although for some sort of security instead of using plain text password, have encoded it using base64 authentication.
- You need to ready with the Payload data json file, before you go ahead and create a new JIRA ticket, this file can be of any name but please content is in JSON format.
Script.
import requests
import json
import base64
from requests.auth import HTTPBasicAuth
# Inorder to encrypt/decrypt your credentials using base64 module as below.
# To encode --> base64.b64encode(bytes("random", "utf-8"))
# To decode --> base64.b64decode("cmFuZG9t").decode("utf-8")
class JiraHandler:
def __init__(self, username):
print('Loading Instnace variables...')
self.username = username
self.securestring = base64.b64decode("replaceItwithYourCredential").decode("utf-8")
self.url = "https://jira.yourownjiradomain.com/rest/api/2/issue/"
def get_jira_details(self,jira_ticket):
try :
auth = HTTPBasicAuth(self.username, self.securestring)
get_details_url = self.url + jira_ticket
headers = {
"Accept": "application/json"
}
print("retrieveing", jira_ticket, "details...")
response = requests.request(
"GET",
get_details_url,
headers=headers,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
except Exception as e:
return e
def create_jira_cr_ticket(self, filename):
get_details_url = self.url
auth = HTTPBasicAuth(self.username, self.securestring)
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
try:
with open(filename, "r") as re_read_file:
payload = re_read_file.read()
print("Creating new JIRA...")
response = requests.request(
"POST",
get_details_url,
data=payload,
headers=headers,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
except Exception as filenotfound:
print("Can't load file..", filenotfound)
import requests
import json
import base64
from requests.auth import HTTPBasicAuth
# Inorder to encrypt/decrypt your credentials using base64 module as below.
# To encode --> base64.b64encode(bytes("random", "utf-8"))
# To decode --> base64.b64decode("cmFuZG9t").decode("utf-8")
class JiraHandler:
def __init__(self, username):
print('Loading Instnace variables...')
self.username = username
self.securestring = base64.b64decode("replaceItwithYourCredential").decode("utf-8")
self.url = "https://jira.yourownjiradomain.com/rest/api/2/issue/"
def get_jira_details(self,jira_ticket):
try :
auth = HTTPBasicAuth(self.username, self.securestring)
get_details_url = self.url + jira_ticket
headers = {
"Accept": "application/json"
}
print("retrieveing", jira_ticket, "details...")
response = requests.request(
"GET",
get_details_url,
headers=headers,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
except Exception as e:
return e
def create_jira_cr_ticket(self, filename):
get_details_url = self.url
auth = HTTPBasicAuth(self.username, self.securestring)
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
try:
with open(filename, "r") as re_read_file:
payload = re_read_file.read()
print("Creating new JIRA...")
response = requests.request(
"POST",
get_details_url,
data=payload,
headers=headers,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
except Exception as filenotfound:
print("Can't load file..", filenotfound)
How to use it,
- Load Instance variable by calling class and provide your JIRA username as an input.
# Initiate Class and load instance variable.
d = JiraHandler("your_JIRA_Username")
- Call method get_jira_details and add JIRA ticket as method input, for example if we want to get details about a specific JIRA ticket CKPROJ-6162, we must call the method as described below.
# Call below method to get JIRA ticket details.
d.get_jira_details("CKPROJ-6162")
- Before calling method create_jira_cr_ticket, dump json content within a json file, for instance i have created a file named payload_data.json and it looks somehow like below.
- Thinking how to find it, use method get_jira_details, it will give you an idea for the field used within your project's jira ticket.
{
"fields": {
"project":
{
"key": "CKPROJ"
},
"summary": "My Dummy Ticket created by REST API",
"description": "Dummy CR for REST API Test",
"confluence": "Dummy Confluence Page Link",
"verification_steps": "Verification Plan",
"issuetype": {
"name": "Change Request"
}
}
}
Once you are ready with the payload data, save it within a JSON file and call method providing payload_data.json file as an input to it, as an output script will return the JIRA ticket details.
# Call below method to create new JIRA ticket
d.create_jira_cr_ticket("C:\\Users\\cyberkeeda\\payload_data.json")
Hope this script can have help in any sort, for any help comment please.
van
ReplyDeletekastamonu
elazığ
tokat
sakarya
P36A3
4E8EC
ReplyDeleteManisa Parça Eşya Taşıma
Zonguldak Şehirler Arası Nakliyat
Sakarya Şehir İçi Nakliyat
Çankırı Şehir İçi Nakliyat
Tekirdağ Cam Balkon
Keçiören Boya Ustası
Gümüşhane Şehir İçi Nakliyat
Antalya Şehirler Arası Nakliyat
Yozgat Şehirler Arası Nakliyat
14EF5
ReplyDeleteKarapürçek Fayans Ustası
Altındağ Boya Ustası
Balıkesir Şehirler Arası Nakliyat
Antalya Lojistik
Bursa Şehir İçi Nakliyat
Çerkezköy Korkuluk
Çanakkale Şehirler Arası Nakliyat
Gölbaşı Fayans Ustası
Kırklareli Şehirler Arası Nakliyat
D71F2
ReplyDeleteArtvin Evden Eve Nakliyat
pharmacy steroids
Binance Referans Kodu
https://steroidsbuy.net/
order deca durabolin
order sustanon
fat burner for sale
order sarms
order primobolan
FF860
ReplyDeletekütahya rastgele canlı sohbet
bayburt canlı sohbet bedava
goruntulu sohbet
istanbul canlı ücretsiz sohbet
mersin bedava görüntülü sohbet
kars goruntulu sohbet
mardin parasız sohbet
canlı sohbet sitesi
edirne en iyi ücretsiz sohbet uygulamaları
94EDC
ReplyDeleteKwai Beğeni Satın Al
Alya Coin Hangi Borsada
Twitter Beğeni Satın Al
Tiktok İzlenme Satın Al
Clubhouse Takipçi Satın Al
Yeni Çıkacak Coin Nasıl Alınır
Coin Nasıl Çıkarılır
Periscope Beğeni Satın Al
Nonolive Takipçi Hilesi
108CF
ReplyDeleteCoin Kazma
Sohbet
Kripto Para Madenciliği Siteleri
Spotify Dinlenme Hilesi
Sui Coin Hangi Borsada
Görüntülü Sohbet
Linkedin Takipçi Satın Al
Likee App Beğeni Hilesi
Binance Referans Kodu
51709
ReplyDeleteens coin yorum
knight online sunucu kiralama
freelance iş ilanları
socks5 proxy satın al
celo coin yorum
alpine coin yorum
ankr coin yorum
glm coin yorum
dedicated server
B8F3A
ReplyDeletegörüntülü şov ücretli