We want to migrate some user stories from one workspace to another using 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)
Used "_ref": rec.ref
to see if I can get the associated tasks so that I can migrate them as well
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))
I got below exception
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
The objective is to migrate all the possible data (associated tasks, defects, test cases, task estimates etc.) when we migrate the user story