I am trying to write a transition post function for JIRA v5.x. using the groovyscriptrunner
It should check if there is already a Confluence page linked with the issue, and create and link the page if not. I am developing this using the a groovy script and the scriptrunner plugin which can access the JAVA API.
While it was fairly easy to create the confluence page, I am struggling with the remote issue links.
This is how I try to create the link:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.bc.issue.link.RemoteIssueLinkService import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder //I use a wrapper class for the moment so I can run via scriptrunner and debug it in IDEA class myWrapper { def doStuff() { //get the issue, this would already be available in an post action def issueService = ComponentManager.getInstance().getIssueService(); def authContext = ComponentManager.getInstance().getJiraAuthenticationContext() def issueResult = issueService.getIssue(authContext.getUser(), "DEV-1"); def issue = issueResult.getIssue() //build link def linkBuilder = new RemoteIssueLinkBuilder() linkBuilder.issueId(issue.id) linkBuilder.applicationName("myconf") linkBuilder.applicationType("com.atlassian.confluence") linkBuilder.relationship("Wiki Page") linkBuilder.title("testpage") linkBuilder.url("http://localhost:8090/display/LIN/testpage") linkBuilder.build() def validationResult = RemoteIssueLinkService.validateCreate(authContext.getUser(), linkBuilder) } } (new myWrapper()).doStuff()
When I run the code I get the following exception:
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.bc.issue.link.RemoteIssueLinkService.validateCreate() is applicable for argument types: (com.atlassian.crowd.embedded.ofbiz.OfBizUser, com.atlassian.jira.issue.link.RemoteIssueLinkBuilder) values: [admin:1, com.atlassian.jira.issue.link.RemoteIssueLinkBuilder@180ca9]
For me it looks like I do not get the *RemoteIssueLinkService* correctly,but I do not know what I have to do to fix that.
Community moderators have prevented the ability to post new answers.
You have the answer in the error. It's not a static method, so you need to get an instance of the class first:
def remoteIssueLinkService = ComponentManager.getComponentInstanceOfType(RemoteIssueLinkService.class) remoteIssueLinkService.validateCreate(...)
No worries. The rest of the code looked fairly competent so I assumed you weren't new to it. Otherwise I may have been more touchy feely.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All; With this code i am able to create link between jira issue and confluence page it show link on jira issue but it does not show jira link on confluence page (count of jira issue which are connected to page) so is there any changes required for this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is discussed with working code here: https://jamieechlin.atlassian.net/wiki/display/GRV/Interacting+with+Confluence+from+JIRA
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi All;
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor(); //get the issue, this would already be available in an post action IssueService issueService = ComponentAccessor.getIssueService(); JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext(); IssueResult issueResult = issueService.getIssue(authContext.getLoggedInUser(), "TEST-1"); Issue issue = issueResult.getIssue(); //build link RemoteIssueLinkBuilder linkBuilder = new RemoteIssueLinkBuilder(); linkBuilder.issueId(issue.getId()); linkBuilder.applicationName("Confluence"); linkBuilder.applicationType("com.atlassian.confluence"); linkBuilder.relationship("Wiki Page"); linkBuilder.title("Welcome to Confluence"); linkBuilder.url("http://localhost:8099/confluence/display/ds/Welcome+to+Confluence"); linkBuilder.build(); RemoteIssueLink link = linkBuilder.build(); RemoteIssueLinkService remoteIssueLinkService = ComponentAccessor.getComponent(RemoteIssueLinkService.class); CreateValidationResult createValidateResult = remoteIssueLinkService.validateCreate(authContext.getUser(),link); //.validateCreate(authContext.getLoggedInUser(), link); remoteIssueLinkService.create(authContext.getLoggedInUser(), createValidateResult);
With this code i am able to create link between jira issue and confluence page it show link on jira issue but it does not show jira link on confluence page (count of jira issue which are connected to page) so is there any changes required for this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, how did you create Confluence page from Jira script? Thank you
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 need to call the method on the service, ie:
remoteIssueLinkService.createRemoteIssueLink(...)
> by what the hash tag signifies in your comment
Nothing, it's just what goes in the clipboard when I do "copy reference" from my ide.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Jaimie,
I think my main issue was due to IDE being configured incorrectly. Anyway, I got it to work this way:
import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.link.RemoteIssueLinkManager import org.apache.log4j.Category log.setLevel(org.apache.log4j.Level.DEBUG) log.debug "debug statements" def authContext = ComponentAccessor.getJiraAuthenticationContext() def linkBuilder = new RemoteIssueLinkBuilder() // Setting variables as a test -- these will eventuall represent fields gathered from DB query for bulk upload later. // need actual jira appId / issueID in globalId if you want to make a remote link as opposed to a weblink def globalId = 'appId=350eeaaa-0de6-36d0-bc1d-95761684b830&issueId=275829' def issueId = 323532 // issue id of source issue def linkRel = 'is related to' def linkTitle = 'FOOBAR-35' //pkey of destination issue def linkSummary = 'test' // summary of destination issue def linkUrl = 'https://jira.example.com/support/browse/FOOBAR-35' // destination url def appType = 'com.atlassian.jira' // type of application you are linking to def appName = 'otherJira' // name of application you are linking to // Let's populate builder linkBuilder.globalId(globalId) linkBuilder.issueId(issueId.toLong()) linkBuilder.relationship(linkRel) linkBuilder.title(linkTitle) linkBuilder.summary(linkSummary) linkBuilder.url(linkUrl) linkBuilder.applicationType(appType) linkBuilder.applicationName(appName) // let's create link object def link = linkBuilder.build() // let's add link via RemoteIssueLinkManager ComponentAccessor.getComponent(RemoteIssueLinkManager).createRemoteIssueLink(link, authContext.getUser().directoryUser);
-- for whatever reason, I couldn't get remoteIssueLinkService to work. Almost certainly user error on my part. But thanks all the same for your advice -- it led me to a solution. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie -- silly question. How do I make the link reciprocal? I could have sworn I had it working earlier.. but on second thought, it may have been when I was testing rest api.
Right now, the above code create a good remote link, but it doesn't appear on the target issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not really sure how that works. Do you get a reciprocal link when you do it in the UI?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie; with above code i am able to create link but it give Failed To Load with created link so that it is not created link from confluence side can u please help me on this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
FYI, this code doesn't work out-of-the-box for JIRA 5+ (from what I can tell).
Here's what I had to have just to get it to compile:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.bc.issue.issuelink.RemoteIssueLinkService import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder //I use a wrapper class for the moment so I can run via scriptrunner and debug it in IDEA class myWrapper { def doStuff() { //get the issue, this would already be available in an post action def issueService = ComponentManager.getInstance().getIssueService(); def authContext = ComponentManager.getInstance().getJiraAuthenticationContext() def issueResult = issueService.getIssue(authContext.getUser(), "MYPROJECT-5"); def issue = issueResult.getIssue() //build link def linkBuilder = new RemoteIssueLinkBuilder() linkBuilder.issueId(issue.id) linkBuilder.relationship("Wiki Page") linkBuilder.title("testpage") linkBuilder.url("http://www.mypage.com") def link = linkBuilder.build() def remoteIssueLinkService = ComponentManager.getComponentInstanceOfType(RemoteIssueLinkService.class) def validationResult = remoteIssueLinkService.validateCreate(authContext.getUser(), link) } } (new myWrapper()).doStuff()
But after refreshing the page for the issue "MYPROJECT-5" doesn't show that any links were created. Any suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also check logs for errors.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure what you mean by jira 5+, in the original question you said you were using 5.x. What are you upgrading from and to? I;m not aware of anything that you are using changing in the 5.x range.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Specifically, this line:
import com.atlassian.jira.bc.issue.link.RemoteIssueLinkService
Causes the error:
unable to resolve class com.atlassian.jira.bc.issue.link.RemoteIssueLinkService
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What version? That class hasn't gone anywhere. I'll check it out tomorrow.
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.
Works for me. What jira version?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
I am running Script Runner 3 beta on Jira 6.2.5 I can't get this to work:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.bc.issue.link.RemoteIssueLinkService import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.component.ComponentAccessor import org.apache.log4j.Category log.setLevel(org.apache.log4j.Level.DEBUG) log.debug "debug statements" def authContext = ComponentAccessor.getJiraAuthenticationContext() IssueManager issueManager = ComponentAccessor.getIssueManager() String myissue = "TO-10922" //for testing in console Issue issue = issueManager.getIssueObject(myissue) def linkBuilder = new RemoteIssueLinkBuilder() linkBuilder.issueId(issue.id) linkBuilder.relationship("Wiki Page") linkBuilder.title("testpage") linkBuilder.url("http://www.mypage.com") def link = linkBuilder.build() log.debug "Link dump: " + link.dump() + "\r\n" def remoteIssueLinkService = ComponentManager.getComponentInstanceOfType(RemoteIssueLinkService.class) log.debug "remoteIssueLinkService dump: " + remoteIssueLinkService.dump() + "\r\n"
//remoteIssueLinkService.validateCreate(authContext.getUser(), link).dump()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
having issues posting stuff.. hmm... anyway, Any tips The remoteIssueLinkService changed with jira 6.2 I think. Can't figure out how to get it to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def remoteIssueLinkService = ComponentManager.getComponentInstanceOfType(RemoteIssueLinkService.class) log.debug "remoteIssueLinkService dump: " + remoteIssueLinkService.dump() + "\r\n" remoteIssueLinkService.validateCreate(authContext.getUser(), link).dump()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you're already using the builder, so just call createRemoteIssueLink(link, user).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's no validateCreate... you need to use com.atlassian.jira.issue.link.RemoteIssueLinkBuilder to create a RemoteIssueLink to pass to com.atlassian.jira.issue.link.RemoteIssueLinkManager#createRemoteIssueLink(com.atlassian.jira.issue.link.RemoteIssueLink, com.atlassian.crowd.embedded.api.User)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also -- confused by what the hash tag signifies in your comment:
com.atlassian.jira.issue.link.RemoteIssueLinkManager#createRemoteIssueLink(com.atlassian.jira.issue.link.RemoteIssueLink, com.atlassian.crowd.embedded.api.User)
I can't figure out how to access the createRemoteIssueLink. How do access that method?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie. Sorry -- but still having problems groking in:
def linkBuilder = new RemoteIssueLinkBuilder() linkBuilder.issueId(issue.id) linkBuilder.relationship("Wiki Page") linkBuilder.title("testpage") linkBuilder.url("http://www.mypage.com") def link = linkBuilder.build() createRemoteIssueLink(link)
Gives me this error:
No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.createRemoteIssueLink() is applicable for argument types: (com.atlassian.jira.issue.link.RemoteIssueLink) values: [com.atlassian.jira.issue.link.RemoteIssueLink@25029354]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.