3

I am using the JIRA Python module which is an extension of the REST API to automate the process of deleting and creating issues in JIRA. I am trying to create issues in JIRA using a 'for' loop in my python script that uses imported data that I have collected from another database. I need to format the fields when creating the issue so the data I have can align properly with the appropriate fields in JIRA. My Python code is below for creating the issues and storing the data to put into JIRA which is being stored in custom variables:

df contains 13 columns of data that I want to input into JIRA by creating new issues. Each column represents a different field for an issue in JIRA. Every new issue created in JIRA should get info from each column:

from jira.client import JIRA
import pandas as pd

# Now we input the issues from the export.csv CSV file into the fields
# of new issues that are being created in JIRA to replace the old ones that were 
# deleted

df = pd.read_csv('C:\\Python27\\scripts\\export.csv')

# Set the column names from the export.csv file equal to variables using the      
# pandas python module

# Now do the actual loop to create new issues

for row in df:
    cqid = df['ClearQuest ID']
    summ = str(df.Summary)
    datecreated = df['Date Created']
    dateresolved = df['Date Resolved']
    wistate = df['WI State']
    res = df.Resolution
    affected = df['Affected version/s']
    fixed = df['Fix version/s']
    issue_type = df['Issue Type']
    priority = df.Priority
    comments = str(df.Comments)
    jira.create_issue(project={'key': 'DEL'}, wistate={'customfield_1001': 'WI State'}, res={'customfield_1001': 'Resolution'}, cqid={'customfield_1001': 'ClearQuest ID'}, datecreated={'customfield_1001': 'Date Created'}, dateresolved={'customfield_1001': 'Date Resolved'}, priority={'customfield_1001': 'Priority'}, fixed={'customfield_1001': 'Fixed Version'}, affected={'customfield_10004': 'affected'}, summary=summ, description=comments, issuetype={'name': 'Defect'})

It gives the error:

JIRAError: HTTP 400: "{u'cqid': u"Field 'cqid' cannot be set. It is not on the   appropriate screen, or unknown.", u'wistate': u"Field 'wistate' cannot be set. It is not on the appropriate screen, or unknown.", u'dateresolved': u"Field 'dateresolved' cannot be set. It is not on the appropriate screen, or unknown.", u'res': u"Field 'res' cannot be set. It is not on the appropriate screen, or unknown.", u'datecreated': u"Field 'datecreated' cannot be set. It is not on the appropriate screen, or unknown.", u'affected': u"Field 'affected' cannot be set. It is not on the appropriate screen, or unknown.", u'fixed': u"Field 'fixed' cannot be set. It is not on the appropriate screen, or unknown."}"

Here is some example data that is showing up in JIRA for every single issue created in the comments field:

Issue 1:
0 NaN
1 Found that the Delta would leak packets receiv...
2 The Delta will reset everytime you disconnect ...
3 NaN
4 It's supposed to get logged when CP takes to l...
5 Upon upgrading the IDS via the BioMed menu, th...
6 Upon upgrading the IDS via the BioMed menu, th...
7 Upon upgrading the IDS via the BioMed menu, th...
8 Increased Fusion heap size and the SCC1 Initia...
9 Recheck using build 142+, after Matt delivers ...
10 When using WPA2, there is EAPOL key echange go...
11 When using WPA2, there is EAPOL key echange go...
12 NaN
13 NaN
14 NaN ...

I only want each issue to have its own string values, and not the index numbers or the NaN to show up like this:


Issue 1:
Issue 2: Found that the Delta would leak packets receiv...
Issue 3: The Delta will reset everytime you disconnect ... ...

9
  • try for row in df.itertrows(), see here: pandas.pydata.org/pandas-docs/dev/basics.html#iteration Commented Jul 1, 2013 at 21:13
  • It didn't work unfortunately, I got the error: AttributeError: 'DataFrame' object has no attribute 'itertrows' I believe it is the jira.create_issue part that isn't working in terms of my syntax for the fields, the pandas import part works. Commented Jul 1, 2013 at 21:17
  • typo! df.iterrows() Commented Jul 1, 2013 at 21:20
  • what exactly are you trying to do? pls show df, and how I don't even see you using row anywhere? Commented Jul 1, 2013 at 21:29
  • df contains 13 columns of data that I want to input into JIRA by creating new issues. Each column represents a different field for an issue in JIRA. Every new issue created in JIRA should get info from each column. Commented Jul 1, 2013 at 21:37

1 Answer 1

1

One major flaw with your code is that you are assigning the data before you are looping it.

df = pd.read_csv('C:\\Python27\\scripts\\export.csv')

for row in df:
    cqid = row['ClearQuest ID']
    summary = row.Summary
    jira.create_issue(...)

You most likely need to do something like this.

for row in df.values:
    cqid , summary , value3, value4, value5 = row
Sign up to request clarification or add additional context in comments.

4 Comments

It gave me the error: cqid = row['ClearQuest ID'] TypeError: string indices must be integers, not str...........I believe it is the jira.create_issue part that is not working, not the pandas part, however I did change the loop part so thanks for the help with that part of the code
It would help us if you actually included some example csv data.
@JMan I added a new solution.
I tried something else but it still doesn't help me to solve the jira.create_issue part for the custom fields, which is shown in my error above. Thanks for that though, that helps with the data collection part.

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.