1
votes

I am looking at bulk creating tickets within Jira through python using the JIRA module. I am taking the user inputs to insert them into a dictionary which then creates the ticket within my project in JIRA. This all works fine and the ticket gets created as I would want. However my issue comes when trying to loop through the creation of tickets until I specify a point?

I basically want it to take the user inputs, create the tickets then ask me if I want to create another one. If i specify the letter 'Y' it then prompts the user to fill in the input boxes again and creates another ticket and so on until i specify otherwise.

The code I currently have is:

decision = input("Do you want to create a ticket? ")
project = "My project"

if decision == 'Y':
    issue_dict = {
        'project': {'key':project},
        'summary': input("Please provide a summary "),
        'description' : input("please describe the issue "),
        'issuetype':{'name': 'Story'},
        'assignee': {"name": input("Who is this assigned to ")}
    }

    ticket_id = jira.create_issue(fields=issue_dict)

    print("Created, ticket reference: ", ticket_id)

    decision = input("Do you want to create another ticket? ")

else:
    print("No more tickets")

The error that I get with this code is:

NameError: name 'jira' is not defined

Which is on line 14:

ticket_id = jira.create_issue(fields=issue_dict)

Any help would be greatly appreciated, apologies if its a silly error, I have little experience with python loops!

Thanks :)

Edit: I dont understand how to get the code to run back through the top once its gone through once, sorry!

2
where is the loop ?LinPy
Thats where im stuck, sorry i forgot to put it in. I dont understand how to make it loop back through to the start to take in the inputs again?Matthew Meek

2 Answers

1
votes

use this:

from jira.client import JIRA
jira_options = {'server': 'MY_jira.com'}
jira = JIRA(options=jira_options, basic_auth=(USERNAME, PASSWORD))

def ask_what_to_do():
    decision = input("Do you want to create a ticket? \n")
    if decision == 'Y':
        issue_dict = {
            'project': {'key':project},
            'summary': input("Please provide a summary "),
            'description' : input("please describe the issue "),
            'issuetype':{'name': 'Story'},
            'assignee': {"name": input("Who is this assigned to ")}
        }

        ticket_id = jira.create_issue(fields=issue_dict)

        print("Created, ticket reference: ", ticket_id)

        ask_what_to_do()
    else:
        print("No more tickets \n")
1
votes

Obviously, not to get import error, you have to import jira from somewhere.

decision = "Y"
while decision == 'Y':
   issue_dict = {
        'project': {'key':project},
        'summary': input("Please provide a summary "),
        'description' : input("please describe the issue "),
        'issuetype':{'name': 'Story'},
        'assignee': {"name": input("Who is this assigned to ")}
    }

   ticket_id = jira.create_issue(fields=issue_dict)

   print("Created, ticket reference: ", ticket_id)

   decision = input("Do you want to create another ticket? ")