How can i add Web Link(like confluence link) to issue using groovy?

Kiranped July 25, 2020

I have a web page URL which I want to add as Web Link to Issue(of type bug) in Jira On create

Below code not working (I am using Listener)

import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.RemoteIssueLinkManager

if(issue.getIssueTypeObject().getName()=="Bug"){
RemoteIssueLink link = new RemoteIssueLinkBuilder().issueId(issue.getId()).url("http://test.hostname.com/resource.html").title("Test-Link").build();
ComponentAccessor.getComponent(RemoteIssueLinkManager.class).createRemoteIssueLink(link, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser());
}

1 answer

4 votes
Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 26, 2020

Hi @Kiranped ,

 

Your code seems to be missing the definition of issue, see the bold part before the if, and also you should use getIssueType instead of getIssueTypeObject deprecated in JIRA 7;

import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.RemoteIssueLinkManager

def issue = event.issue

if(issue.getIssueType().getName()=="Bug"){
RemoteIssueLink link = new RemoteIssueLinkBuilder().issueId(issue.getId()).url("http://test.hostname.com/resource.html").title("Test-Link").build();
ComponentAccessor.getComponent(RemoteIssueLinkManager.class).createRemoteIssueLink(link, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser());
}

 

 Also since your listener is attached to Issue created event, you need to confirm in your workflow if the create transition is triggering the Issue created event (check for the last post-function in the create transition)

I've seen some cases that create transition was using Generic Event instead of Issue create, which didn't triggered the Listener. 

Peter Brodt January 13, 2022

Thanks a lot, worked perfect for me (:-

Suggest an answer

Log in or Sign up to answer