jira.transition_issue fails with internal server error

I'm trying to use the python interface to transition the state of a set of issues in an automated fashion.

 

It's lless than clear to me how to even get an issue to go from say an open state to a todo or further in the the workflow.

jira.transition_issue(issue, '10000') 

10000 came from jirashell and printing out the issue.fields.status.id value of a card which I'd taken from the open to the todo state.  So by the logic I ought to be able via python to take a card in an open state and likewise transition it to 10000, aka todo.  It fails with:

 

the error : 

  File "/usr/local/lib/python2.7/site-packages/jira/client.py", line 93, in wrapper

    result = func(*arg_list, **kwargs)

  File "/usr/local/lib/python2.7/site-packages/jira/client.py", line 1098, in transition_issue

    url, data=json.dumps(data))

  File "/usr/local/lib/python2.7/site-packages/jira/resilientsession.py", line 81, in post

    return self.__verb('POST', url, **kwargs)

  File "/usr/local/lib/python2.7/site-packages/jira/resilientsession.py", line 74, in __verb

    raise_on_error(r, verb=verb, **kwargs)

  File "/usr/local/lib/python2.7/site-packages/jira/utils.py", line 120, in raise_on_error

    r.status_code, error, r.url, request=request, response=r, **kwargs)

jira.utils.JIRAError: JiraError HTTP 500

 text: Internal server error

2 answers

1 accepted

Accepted Answer
0 votes

Here's the python solution, which is what I'm working with.  The transition IDs are part of the Workflow view, but not everyone can see those IDs. In my case I can see the graph but JIRA doesn't actually display what the IDs are in order to make it work.

So one must do a little reverse engineering. 

If you visit : https://your.url.here/rest/api/2/issue/SOMEISSUE-XX/transitions

And then take that output and drop it in here : http://jsonviewer.stack.hu

resulting in something like ....

"id": "811",
"name": "To Do",
    "to": {

   ....

You'll note that for the start of each section is an id and a number. Those are the numbers that you need and they CAN be different so you'll want to look at an issue in every one of the states and dump out their transitions to see what the ids are. 

So for me 

jira.transition_issue(issue, '811')   moves an object from Open to ToDo.

 

Now I will mention that you ought to be able to get this info out of jira.transitions(issue) but alas my Python isn't that great and that object that comes back it wasn't obvious to me how to walk through the structure....  

Try something like this:

import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.crowd.embedded.api.User;
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
workflowTransitionUtil.setIssue(issue);
workflowTransitionUtil.setUsername(user);
workflowTransitionUtil.setAction (101); // 101 == Transition ID
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

Looking for anyone who made the switch to Data Center

The Jira Marketing team is putting together an ebook on migrating to Data Center. We're looking for pro tips on how you staffed your project team and organized your Proof of Concept. Share yo...

36 views 0 2
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you