#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
sys.path.append('/usr/lib/python2.7/site-packages')
# 安装jira 模块: pip install jira
import jira
from jira import JIRA
import os
# issueName="ANDY-1"
#获取jenkins传入的参数issueName
issueName=os.environ["issueName"]
# 获取jenkins传入的参数transitionID
transitionID=os.environ["transitionID"]
#判断如果参数为空,则退出程序且不报错
if issueName == "none":
print ("无需更改jira问题状态")
sys.exit(0)
print("当前选择的BUG ID为: " + issueName)
# 配置jira
myjira = JIRA('http://jira.zznode.com/',basic_auth=('administrator', 'asb#1234'))
print(myjira.user(myjira.current_user()))
#指定需要改变状态的缺陷
myissue = myjira.issue(issueName)
#获取该问题的可选状态
transitions = myjira.transitions(myissue)
print(transitions)
#print(transitions)
status=[(t['id'], t['name']) for t in transitions]
print("该问题当前可选的状态为: " )
for i in status:
print(i)
#修改问题的状态
myjira.transition_issue(myissue,transitionID)