I would like to the same behaviors
I'm not sure this is the best forum for your question.
But it got me curious even though I'm not much of a python guy and I had never used groovy command line.
I installed groovy and used the same subprocess.Popen to start a simple script.
While documentation says it should be possible for a groovy script executed with the .../bin/groovy should be able to return a final value, I wasn't able to get that behaviour either from a shell command line of from python Popen.
So I would say your best bet is to make sure that your script doesn't output anything other than your final value.
Here is my groovy script:
println "my return value with ${args.size()} arguments: ${args.join(',')}"
return "not printed"
Here is my python script:
import subprocess
p = subprocess.Popen(["/snap/groovy/current/bin/groovy", "/path/to/script.groovy", "arg1", "arg2"],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print out
Here is the output
>>> my return value with 2 arguments: arg1,arg2
Before looking all this up, my instinct would have been to tell you that you can call the scriptrunner groovy engine running inside jira using curl command:
$ curl -X POST "http://127.0.0.1:8080/rest/scriptrunner/latest/user/exec/ -H "X-Atlassian-token: no-check" -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "Accept: application/json" --data-urlencode "scriptText@/path/to/script.groovy" -u <user>:<password>
Hope this helps.
Hi, I have no issue running groovy script through python locally.
What fails is doing the same thing in scriptrunner workflow because of the aforementioned "lack of permissions" to (i think) groovy excutable.
We don't want to run it through REST. Although you say that scriptrunner groovy engine can be accessed through it. Which means it has to be installed with plugin itself, is there any way to call it locally on jira itself? Any specific path to it maybe?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Groovy in jira/scriptrunner is embedded into the scriptrunner plugin via the inclusions of libraries.
There are no executable that you can reach via the command line.
Once you start execution of a python script in a shell, you can't access the JVM components anymove other than through an externalized endpoint. And the only one I am aware of is the rest endpoint.
Here is a quick POC I did (expanding on the example before).
groovy script stored in /apps/tmp/test.groovy:
println "this output is from groovy script. ${args.size()} arguments: ${args.join(',')}"
return "not printed"
Python file stored in/apps/tmp/test.py
import subprocess
print "This output is from the python script before calling groovy"
p = subprocess.Popen(["/snap/groovy/current/bin/groovy", "/apps/tmp/test.groovy", "groovy arg1", "groovy arg2"],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print "This output is from the python script after calling groovy"
out, err = p.communicate()
print out
Code in scriptrunner groovy console:
def proc = """python2 /apps/tmp/test.py """.execute()
def sout = new StringBuilder()
def serr = new StringBuilder()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(10000)
if(serr) log.error serr
log.info sout
Output
2022-07-04 13:36:23,652 INFO [runner.ScriptBindingsManager]: This output is from the python script before calling groovy
2022-07-04 13:36:23,653 INFO [runner.ScriptBindingsManager]: This output is from the python script after calling groovy
2022-07-04 13:36:23,653 INFO [runner.ScriptBindingsManager]: this output is from groovy script. 2 arguments: groovy arg1,groovy arg2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, what's the 'snap' directory? Did you install groovy on jira server via snap package?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Like I said. I had never used groovy from the command line. That was just the first result I found when I searched for how to install groovy on RHEL.
https://snapcraft.io/install/groovy/rhel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately we do not use systemd and apparently snap needs it(the solution in provided link for OS without it does not work). Thanks tho
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.