As stated here:https://scriptrunner.adaptavist.com/4.2.0.2/jira/builtin-scripts.html#_executing_built_in_scripts_remotely
To execute a file that already exists under a script root:
> curl -u admin:admin -X POST "http://<jira>/jira/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 "scriptFile=foo/bar.groovy"
I can already execute a script fine, but now I need to send a parameter, through curl to my script. And how can i receive and read it in my script?
I cant seem to find a way to do it.
This is equivalent to pasting the content on foo/bar.groovy into the console and hitting run.
The only way to pass parameters to such a script is to use the "dynamic form" feature
Looking at browser network call when you hit run, you can see that the payload includes 2 elements. A "parameters" json and the script string or scriptPath.
I haven't tried with curl, but you can try something like this
-H "Accept: application/json" --data-urlencode "scriptFile=foo/bar.groovy" --data-urlencode 'parameters={\"param1\":\"value\"}'curl -u admin:admin -X POST "http://<jira>/jira/rest/scriptrunner/latest/user/exec/" <br>-H "X-Atlassian-token: no-check" <br>-H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" <br>
Not sure I have the right escaping.
I'm not a curl wizard, so maybe you can pass --data-urlencode "scriptfile=..." and some other type in the same command.
Alternatively, you could have your script file be dynamically pre-loaded with your variables.
I have the following in a shell script I use to automatically port prod data to my test instance:
folderName="TEST"groovy=$(cat <<-EOM 2>&1 import com.atlassian.jira.component.ComponentAccessor def mailFetchers = ComponentAccessor.serviceManager.getServices().findAll{it.serviceClass == 'com.atlassian.jira.service.services.mail.MailFetcherService'} mailFetchers.collect{mailFetcher-> def folderName='$folder' mailFetcher.properties.setString('foldername', folderName) "Set foldername for mailFetcher.name to '\$folderName'" }EOM)result_code=$(echo "$groovy"| curl -s -o /dev/null -w "%{http_code}" -u "$user":"$password" -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@-")if [[ "$result_code" == "200" ]];then echo " Mail Handler update successful"else echo " Mail Handler update was not successful. Review mail handler folders in the application"fi
Hi;
Thanks, what you said gave me the clue on how to get the curl call with the correct parameters.
The call is similar to what you were saying.
curl 'https://[jira]/rest/scriptrunner/latest/user/exec/' \-H 'Accept: application/json' \-H 'X-Atlassian-token: no-check' \-H 'Content-Type: application/json' \-u user:pswd \--data-raw '{"script":null,"scriptPath":"testscript.groovy","parameters":{"valueToAdd":"10"}}'
That should do the trick.
Thanks a lot.
It looks like you're new here. Sign in or register to get started.