Hi everyone,
I`m trying to do a test integration of two jira instances using Script Runner.
On first instance the code (see below) during the transaction call an event and this event run the code on listener in scriptrunner.
This code its ok with green symbol and run. But anything happend. I knew that this is a simple test, but I don`t know what is my mistake.
Can someone help me ?
import groovy.json.StreamingJsonBuilder
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.text.SimpleDateFormat
import java.text.DateFormat
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
def baseURL = "http://localhost:8081/rest/api/2/issue";
// localhost:8081 it`s the target instance
def authString = "admin:admin".getBytes().encodeBase64().toString();
def body_req = [
"""
{ "fields":
{
"project":
{
"key": "PT"
},
"summary": "My Issue.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype":
{
"name": "Bug"
}
}
}
"""
]
URL url = new URL(baseURL);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setRequestProperty( "Authorization", "Basic ${authString}" );
connection.requestMethod = "POST";
connection.doOutput = true;
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }
connection.connect();
Problem resolved,
I just forget the / after issue.
before
def baseURL = "http://localhost:8081/rest/api/2/issue";
after
def baseURL = "http://localhost:8081/rest/api/2/issue/";
I have used your script to create an issue but it is not throwing any error or creating the issue. Can you help me why is it so?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You could resolve this.. sorry for delay.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fabio,
I can't tell you the exact solution, but maybe how you can get there. Why don't you integrate some logging into your script as described in the Scriptrunner docs? You could furthermore write a try-catch block around everything beneath your import statements and log the error (or act accordingly).
Having said that, I'd like to ask you what you are accomplishing to do - obviously you want to create an issue on another instance. But what is your further intent? Keeping the two issues in sync?
We are developing an issue sync app: Backbone Issue Sync for Jira.
Backbone allows you to simply create issues in another Jira as well as keeping them in sync afterwards. You can configure in a UI all the data you want to exchange (fields, issue types, workflow states, ...) and don't have to wrestle with groovy scripts.
If you think that is helpful to you, give it a try. And let us know via support@k15t.com if you need a demo or any other help.
Cheers,
Matthias
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Matthias,
Good idea about put logging into my script. The intention its just sync issues in both instances, but buy another app is not an option at this moment.
I'll continue with my tests.
Thanks,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fine with me, Fabio.
I simply want to point you to possible solutions which might save you some time. You choose yourself your best option. :)
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.