I need to take some action in a workflow transition on Jira cloud and It depends on the user.
How do I get the transitioning user (who triggered the post function) in a script runner post function?
You configure the post-function to run as the initiating user, then in the function you can call
def result = get('/rest/api/3/myself').asObject(Map)
to get the identity of the initiator. However, if you do this, your script might not be able to do its job due to lack of permissions.
The hackish solution to this is to add another "trigger" transition (from the status on which you had the initial post function, to the same status - self loop transition), which you set to run as the initiating user, and from which you store the caller user's identity on the ticket and then programmatically invoke the real transition. Then you mark the transition that does the real work to run as the Scriptrunner add-on. Finally, in the post function that does the real work you will have the initiating user in a custom field of the ticket.
Keep in mind that self-loop transitions will not show under the Transitions and statuses dropdown but under the Automations one (the next one to right)
The only slight problem left is that you now need to hide the transition that does the real work from the regular users. Restrict it to Jira admins?
Or just bite the bullet, run the post function as the initiating user, then call the endpoints that the initiating user cannot call by authenticating as some user that has the right permissions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.