Can you create a comment as part of a ScriptRunner Post Function that is owned by the system user?

Bruce Mohler September 26, 2019

We can write a Groovy Post Function script to post a comment to an issue based on some triggering event but the owner of the comment is the currently logged in user.

Is it possible to post that comment as a Jira "system" user (for example, "administrator")?

Is that a lot of work to accomplish?

1 answer

1 accepted

0 votes
Answer accepted
Randy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2019

Yes you can.  Change the dropdown so the script runs as the Scriptrunner Add-on user account

Bruce Mohler September 26, 2019

Thanks, @Randy .

Since I can't find a "Scriptrunner Add-on" account in the User Manager, do you happen to know what the name of the account is?

Is it always there even if I can't find it in User Manager?

Bruce Mohler September 26, 2019

Also, do you happen to have a snippet of code to change to that user account?

Randy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2019

Ah i missed that you're on server.  I believe you would use:

 

ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(user);

Pass the user you want to impersonate as the parameter of setLoggedInUser 

Randy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2019

Just as a general rule you should avoid using an administrator account.  Setup an account with specific rights/access for the tasks you need to run with it.

Bruce Mohler September 26, 2019

Ah, got it.  Thanks, @Randy .

Like Randy likes this

Suggest an answer

Log in or Sign up to answer