Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Using scriptrunner to call the current issue key, send the reporter id to a shell script

Michael Salvio July 12, 2020

I have worked out part of the issue. I can get the code to activate a shell script on the server side when an issue passes through a transition containing the scriptrunner post function. The code also send the reporter ID parameter to the shell script. However I can only get this to work when I manually enter the issue key. Can anyone assist with allowing the code to pull whatever issue key it is running on? Thank you!

Original code (manual key entry):

import com.atlassian.jira.component.ComponentAccessor

def issueId = "TES-123" // test parameter, change me later
def issueReporter = ComponentAccessor.getIssueManager().getIssueObject(issueId).reporter

def sout = new StringBuilder()
def serr = new StringBuilder()
def cmd = "/home/smithj/account.sh"
def proc = new ProcessBuilder(cmd, issueReporter.username).start()
proc.consumeProcessOutput(sout,serr)
proc.waitForOrKill(30000)
if(serr){
log.error "Error exeucting shell script with standard error output: \n $serr"
log.debug "Erroring shell script had standard output:\n $sout"
} else {
log.debug "Shell script executed succesfully with standard output:\n $sout"
}

 

2 answers

1 accepted

0 votes
Answer accepted
Ismael Jimoh
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.
July 12, 2020

Hi @Michael Salvio 

If this is from a workflow post function then use issue.key to get the issue key.

Michael Salvio July 13, 2020

Hello @Ismael Jimoh 


Thank you so much! Worked like a charm!

Aye Aye Pyone November 2, 2020

OK Dollar မွ ႀကိဳဆိုပါတယ္။ သင့္ လွ်ိဳ႕၀ွက္နံပါတ္သည္ H4BF4JE3II2Fc6Hb8JJ1a ျဖစ္သည္။ သင္ယခု လွ်ိဳ႕၀ွက္နံပါတ္ကို အသံုးျပဳၿပီးပါက လံုၿခံဳေရး အရ ယခု စာတိုကို ဖ်က္ပါ။

0 votes
Jeff Olvera
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 30, 2023

I am working on a similar setup but I am attempting to run a scriptrunner script inline within project automation. How do i pull the issue key from the issue that triggered the automation?

Ismael Jimoh
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.
December 4, 2023

Hi @Jeff Olvera ,

I will typically raise a new request for this.

If you are using scriptrunner, then I will expect issue.key to give you the key if you are running this from the workflow itself.

If you are speaking of using automation for JIRA (this is different from scriptrunner), consider using {{issue.key}} which will get you the actual issue key if it involves branching rules then try {{triggerIssue.key}}.

Read more about project automation/automation for JIRA here.

I hope that helps.

Regards

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.8
TAGS
AUG Leaders

Atlassian Community Events