I supposed that your Python environment has been installed
1. Installation of JIRA-Python package
Pip install jira
2. Connect to JIRA
(1) Without Authentication
def connect_jira(jira_server):
try:
jira_options = {'server': jira_server}
jira = JIRA(options=jira_options))
return jira
except Exception,e:
return None
(2) Basic Authentication
def connect_jira(jira_server, jira_user, jira_password):
try:
jira_options = {'server': jira_server}
jira = JIRA(options=jira_options, basic_auth=(jira_user, jira_password))
return jira
except Exception,e:
return None
3. Create a JIRA story object
jira = connect_jira("https://jira.#########.com")
issue =jira.issue('JRA-1330')
print issue.Key
4. Get all stories for specific sprint
sprint = '####'
issues = jira.search_issues('sprint=%s and type=Story' % sprint)
for iss in issues:
print iss.key
5. Get all bugs which labels contain 'regression'
sprint = '####'
bugs = jira.search_issues('sprint=%s and type=Bug and labels in ("regression")' % sprint)
for bug in bugs:
print bug.fields.summary
6. Get all linked bugs of a story
issue = jira.issue('JRA-1330')
issuesLinked = jira.search_issues('issue in linkedIssues(%s) and type=bug' % issue.key)
7. Create an issue
issue_dict = {
'project': {'key': 'RIO2016'},
'summary': 'New issue created from jira-python',
'description': 'just for test',
'issuetype': {'name': 'Bug'},
}
issue = jira.create_issue(fields=issue_dict)
8. Set fixVersion
def set_fixversion(issue_object, project_name, version_name):
versions = jira.project_versions(jira.project(project_name))
for version in versions:
if(version.name == version_name):
issue_object.update(fixVersions=[{"id" : version.id}])
return True
return False
issue = jira.issue('RIO2016-774')
set_fixversion(issue, 'RIO2016', '15-1 04/08/2015')
9. Add a new comment
comment = jira.add_comment('RIO2016-774', 'a new comment, just for test')
10. Get history of an issue
issue = jira.issue('RIO2016-504', expand='changelog')
changelog = issue.changelog
for history in changelog.histories:
for item in history.items:
if item.field == 'status':
print history.created
print getattr(item,'fromString')
print getattr(item,'toString')
11. Get json of an issue
import json
issue = jira.issue('RIO2016-504')
print json.dumps(issue.raw)
You also can get more details about jira-python API in page: http://jira-python.readthedocs.org/en/latest/