使用python拉力API将相关任务和缺陷与用户故事一起迁移

时间:2017-04-07 11:00:19

标签: python rally code-rally

我们希望使用API​​将一些用户故事从一个工作区迁移到另一个工作区。

import sys
from pyral import Rally, rallyWorkset
options = [arg for arg in sys.argv[1:] if arg.startswith('--')]
args    = [arg for arg in sys.argv[1:] if arg not in options]
server = "rally1.rallydev.com"
apikey = "<api key>"
workspace = "<Source workspace>"
project = "<target workspace>"
rally = Rally(server,apikey=apikey, workspace=workspace, project=project)
rally.enableLogging('mypyral.log')

# Fetch the data for source user story
response = rally.get('UserStory', fetch=True, query='FormattedID = US2156')
for rec in response:
    print(rec.details())

# Switch to target workspace
rally.setWorkspace("<target workspace>")
rally.setProject("<Target Project>")
print(rec.oid, rec.Name, rec.Attachments)

使用"_ref": rec.ref查看我是否可以获取相关任务,以便我也可以迁移它们

rec = { "Name": rec.Name, "Attachments": rec.Attachments, "ScheduleState": rec.ScheduleState, "Description": rec.Description, "_ref": rec.ref }
try:
    userstory = rally.create('UserStory', rec)
except (RallyRESTException, ex):
    sys.stderr.write('ERROR: %s \n' % details)
    sys.exit(1)
print("UserStory created, ObjectID: %s  FormattedID: %s" % (userstory.oid, userstory.FormattedID))

我得到了以下异常

Traceback (most recent call last):
  File "migrate.py", line 23, in <module>
    userstory = rally.create('UserStory', rec)
  File "C:\Users\dedileep\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyral\restapi.py", line 990, in put
    itemData = self.validateAttributeNames(entityName, itemData)
  File "C:\Users\dedileep\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyral\restapi.py", line 1447, in validateAttributeNames
    raise RallyAttributeNameError(", ".join(invalid_attrs))
pyral.restapi.RallyAttributeNameError: _ref

目标是在迁移用户故事时迁移所有可能的数据(相关任务,缺陷,测试用例,任务估算等)

0 个答案:

没有答案