1

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 ? Commented Nov 19, 2019 at 12:07
  • 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? Commented Nov 19, 2019 at 12:08

2 Answers 2

1

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")
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for this! It seems to work through but then I still get the "name 'jira' is not defined" when trying to create the ticket?
did you import the correct jira lib in your script ?
Thats what I am just checking, i will let you know :)
Yep was down to my error with installation so all fixed now and this works perfectly. Thank you!
1

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? ")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.