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