Here is the scenario I want to implement:
I have a script in the Jira server that I need to execute during a transition. I used the Script Post-Function by ScriptRunner and I can confirm that the script is triggered. However, some commands in the script needs the details of the issue that underwent the transition as their input parameters.
I've been searching for similar questions for a while. Most of what I found were using groovy scripts to GET via REST API but the requests still need a JQL requiring issue details that I need in the first place.
Is there a way for the Script Post-Function to send or write the details of the issue that triggered it to the script? Or write the issue JSON to a file so I can just grep the details I need and put it in the script?
Thank you.
When you're writing a post-function script, you have direct access to the issue without having to do anything.
The object issue is passed into the script for you to work with directly, so you can do things like issue.getSummary() without importing anything.
Thanks for answering Nic. Is there a way to print them locally in the server so they can be used by the script (I forgot to mention that the script is a bash script)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you're calling a bash script, then the call to it is some form of "exec" statement, in which you can include parameters.
Let's say you had a bash script that simply said
echo $1
Then the code calling it in your post-function can say something like
exec ("/data/scripts/myjirascript.sh " + issue.getSummary() )
and you'll get the issue summary dumped out to the log.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Nic,
To test, I created a script called myscript.sh with the following contents:
echo $1 > /path/to/myscript.log
I created this post-function:
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = '/path/to/myscript.sh + issue.getKey()'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println sout
During the desired transition, the log file is created but there's nothing written to it. I also tried this one:
def sout = new StringBuffer(), serr = new StringBuffer()
def command = 'sh /path/to/myscript.sh' + issue.getKey()
def proc = command.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println sout
But it's worse as it doesn't create the log file at all.
I checked the Jira logs and all the issue details and fields are there instead of just the issue key.
Any hints where I went wrong? Sorry for the questions as I have no prior experience with groovy scripts. Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, no, it won't. Look at the command you are executing - let's say you have an issue ABC-123, your command will say
sh ./path/to/myscript.shABC-123
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What a stupid mistake :( It's working now. Thanks for the help Nic!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.