Hey there,
I'm completely new to JIRA, and as my first task, i wanted to write a groovy script, which "clones" an issue, when its state changes (i know that there's a build-in script for that, but thats not how you learn) ... So I installed the Script Runner Plugin by Jamie Echlin and everything worked great. Well, kinda, but thats not my topic atm ;-) Then out of the blue, the script wasn't executed anymore, although the script is integrated in the workflow.
Google didn't really help this time, so i'm wondering if anyone (more experienced than me) has encountered this issue, and knows a work-around.
Thanks for your help in advance
edit:
The Process in a little more detailed:
I Wrote a script, added it to a transition, manually changed the Issue State to "activate" the script, the script did something, i updated the script, tried to "activate" the script again and suddenly not one of the scripts requests was executed.
Well, you definitely receive 400 request from your PUT query. Could you please check your description, comment body and summary you are trying to add? maybe you break the json when you do such kind of construction.
Please think about construction of json object with that class:
i.e. you have a single double quote in one of those variables
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Its definetly not the REST part ;-) just tested it out, by commenting the JIRA API part, executed the transition, the script was executed, and the REST request worked perfectly.... So this leaves me with the JIRA API part... question is, why is it messing up my script?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
well the error is strict - bad request of your PUT method. Could you please try to add logging and log your json object you are sending when you receive that error - and put that object here?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1. I don't see where do you authenticate. As you are opening new client and connection - it is possible you shoud authenticate again
2. You've choosen complex way of updating the issue. There is no need to call REST API to update fields, you can use internal JIRA API without http calls. Please look into https://docs.atlassian.com/jira/latest/com/atlassian/jira/bc/issue/IssueService.html for the information how to update issue. See https://developer.atlassian.com/display/JIRADEV/Performing+Issue+Operations for details
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@1. Lol, i had to cut the auth part because my comment was limited to 2000 chars ;-) its in there, and it works :)
@2. I know that, the reason i used REST is, that when the script runs properly, it should be activated in an external JIRA System, get some data from its activating Issue, and then create a new Issue in my Local JIRA system, with a reference to the original object. And to do that, i definetly need REST
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I should also mention: When i cut the JIRA API part, and execute the script in Eclipse, it works just fine. So, the question persists, why is it, that the requests aren't executed, when run as a postscript (altough it worked countless times)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Alexey for helping. My comment would be to use JsonBuilder to convert from a map to json, don't try to do it yourself or it will blow up when someone uses a } in the description.
My other comment would be to use trusted apps to make the request, so you don't have to bother with the authn. I've posted an example before on doing this, somewhere.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thx Jamie ;-)
like I said, it WASN'T your Scriptrunner :D It WAS my missing knowledge in regards to Groovy. Now i know, that a \n will mess up the JSON one's trying to send, when using REST, everything works fine ;-) It actually works so nicely, that the only function of my script im pondering about is, how i can handle Validators, when transitioning via Script. But thats not the point of this topic, so i wont go into detail on what problems this is causing me ;-)
Btw, i thought i'd already closed this question, did i forget a step?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When you've created a ticket there is a checkbox near each answer - you can select the suitable and mark that answer as correct
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.
> Btw, i thought i'd already closed this question, did i forget a step
I don't know, but I don't let a question being closed prevent me from chiming in ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am glad that it helped) Mark the question as answered to close it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, it took me some time to figure it out, BUT now i got it.... You were right Alexey, the json was messed up. Thanks to the newline I tried to add to my "description" string. What i had forgotten was, that you have to cancel out the "\" of \n by adding another backslash. So, the corect code would've been: "\\n".... thanks for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
atlassian-jira.log is the point of interest
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
2014-08-15 11:57:30,494 http-bio-8080-exec-1 ERROR admin 717x2514x1 uy9yrg 127.0.0.1 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] ************************************************************************************* 2014-08-15 11:57:30,495 http-bio-8080-exec-1 ERROR admin 717x2514x1 uy9yrg 127.0.0.1 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: JIRA-1, actionId: 11, file: C:\Program Files\Atlassian\Application Data\JIRA\scripts\JiraTest.groovy groovyx.net.http.HttpResponseException: Bad Request at groovyx.net.http.RESTClient.defaultFailureHandler(RESTClient.java:240) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:508) at groovyx.net.http.RESTClient.put(RESTClient.java:162) at groovyx.net.http.RESTClient$put.call(Unknown Source) at JiraTest.run(JiraTest.groovy:96)
thats the interesting part of this log ^^ As far as i see it, the thrown exception is Bad Request, but i haven't changed the URI, any other reasons why this could happen?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think there is some caused by... part that is more interesting. Now I suppose it is time to share your code, as seems that you are executing it properly )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks, the complete code'd be:
(The JIRA API part doesn't have to be correct. As i mentioned, i'm a beginner, and this is just a "test" to get used to JIRA API. Important is, that the Put request isn't executed)
import groovyx.net.http.RESTClient; import groovyx.net.http.HttpResponseDecorator; import org.apache.http.HttpRequest; import org.apache.http.protocol.HttpContext; import org.apache.http.HttpRequestInterceptor; import static groovyx.net.http.Method.* import static groovyx.net.http.ContentType.* /*** JIRA API ***/ import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.FieldManager /*** Variables ***/ def jiraApiUrl, usr, pwd, project def summary = "Postscript " + new java.text.SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ssZ").format(new Date()) def description = "" def commentBody = "Postscript" + new java.text.SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ssZ").format(new Date()) jiraApiUrl = "http://localhost:8080/rest/api/latest/" usr = "*******" pwd = "*******" project = "*****" /*** JIRA API testing Code ***/ description = "getAllAvailableNavigableFields() w/NL : " ComponentAccessor ca = new ComponentAccessor() FieldManager fm = ca.getFieldManager() srcFields = fm.getAllAvailableNavigableFields() srcFieldIt = srcFields.iterator() while(srcFieldIt.hasNext()) description = description + srcFieldIt.next().getNameKey() + "\n" /*** Connection ***/ def jiraClient = new RESTClient(jiraApiUrl); /*** Simple PUT Request ***/ def query = '''{"fields": {"description": "''' + description + '''", "summary":"''' + summary + '''" }, "update": {"comment": [{"add" : { "body": "''' + commentBody + '''"} } ] } }''' def putPath = "issue/${project}-3" jiraClient.put(path : putPath, body: query, requestContentType : JSON)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have a look in Admin -> System Information, that should give you the full path to the log (easier than telling you to look in jira-home/logs/atlassian-jira.log ...)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
https://confluence.atlassian.com/pages/viewpage.action?pageId=16121981- info about log files.
As for the usage - ok, you've copied, and then how did you execute it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexey: I added it as a post function, so it was executed, when an Issue transitioned from State A to State B. In My case it was the transition from State: To-Do, to State: In-Progress.
@Nic: thx, i found a bunch of logs, which one is of interest in this case?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sure sure,
how i saved the script: Well, i just saved it in eclipse, copied it from my src folder to my Jira Script folder, which answers the next question:
where is the script located: C:\Program Files\Atlassian\Application Data\JIRA\scripts, i guess its the standart path.
errors in log: couldnt find a log, any hints where to look? Like i said, i'm completely new to JIRA
i just find it particularly strange, that i was able to run the script a dozen times after "updating" it, and suddenly it doesn't work anymore....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please provide more details on how do you saved the script, where is it located and what are the errors in log if exist
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.