简体   繁体   中英

python script to check Jira status

I need a python script that will check Jira status in particular time interval(1 minutes) and once Jira ticket status is approved it will break the loop and proceed with further step(command: terraform apply). Could you please help out with code.

Using curl to fetch the Jira status:

curl -u username:password -X GET -H "Content-Type: application/json" https://server-url/rest/api/2/issue/JRA-1?fields=status

You can refer to the following program this will resolve this issue

import time
import json, sys, requests, os

def getStatus():
    url = "https://server-url/rest/api/2/issue/JRA-1"
    headers = {
    "Accept": "application/json",
    "Authorization": "Basic base64encodethese(username:password)"
    }
    response = requests.request(
    "GET",
    url,
    headers=headers
    )
    jsonResponse = json.loads(response.text)
    return jsonResponse["status"]

def main():
    while(getStatus != "APPROVED"):
        time.sleep(50) 
    os.system("terraform apply")

Checking Jira status every single minute might to demanding for the server -- eg if it happens too long (24/7) and/or if many other similar requests are sent to the server.

Alternatively, you can discuss with Jira administrators to adjust the workflow. Once the issue is transitioned to APPROVED status, they can trigger/call terraform tasks (via webhooks). Only one call is sent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM