Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Is it possible to to create in ticket a link to a page in confluence using scriptrunner in jira post function?
The option described in the docking is not suitable, The page is needed in the wiki.
On the confluence side, I create a ticket backlink using {jira: key = $ {issue.key}} in the pagebody. But I do not understand how to create a link of the "Confluence page" type on the jira side.
import com.atlassian.applinks.api.ApplicationLink
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.jira.issue.Issue
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import com.atlassian.sal.api.net.ResponseHandler
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def ApplicationLink getPrimaryConfluenceLink() {
def applicationLinkService = ComponentLocator.getComponent(ApplicationLinkService)
final ApplicationLink conflLink = applicationLinkService.getPrimaryApplicationLink(ConfluenceApplicationType)
conflLink
}
Issue Issue = issue
def confluenceLink = getPrimaryConfluenceLink()
assert confluenceLink
def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()
def pageTitle = issue.key + " Discussion" as String
def pageBody = """h3. ${issue.summary}
{jira: key = ${issue.key}}
{quote}${issue.description}{quote}
"""
def params = [
type : "page",
title: pageTitle,
space: [
key: "testovoe"
],
body : [
storage: [
value : pageBody,
representation: "wiki"
],
],
]
authenticatedRequestFactory
.createRequest(Request.MethodType.POST, "rest/api/content")
.addHeader("Content-Type", "application/json")
.setRequestBody(new JsonBuilder(params).toString())
.execute(new ResponseHandler<Response>() {
@Override
void handle(Response response) throws ResponseException {
def webUrl = new JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]
def newurl = webUrl as String
def newweb = "https://my.confluenceserver.com" + newurl -"]"-"["
log.debug newweb
}
})
Normally, when you create a jira issue macro in a confluence page, it automatically creates a link back to the source confluence page in the jira issue as "mentioned in <pagename>". But that doesn't seem to happen automatically when creating using api this way.
Is this what you are trying to achieve?
Or are you asking how to include a link to another pre-existing page in the wiki pageBody?
If so, something like this should work:
def pageBody = """h3. ${issue.summary}
{jira: key = ${issue.key}}
{quote}${issue.description}{quote}
[Link To Page|Name of the page to link to]
"""
Hello, Peter-Dave Sheehan
The automatic link in jira to wikipage does not work in this case and it makes me sad.
I just need to create a link on the Jira side.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I played around with this ... try to generate your pagebody jira macro with additional attributes
{jira: key=${issue.key}|serverId=xxx-xxx-xxx-xx|server=yyy}
Get the xxx-xxxx and yyy values from a macro that you insert manually. It will be the application id and name from your confluence applinks
When I specify both of those parameters, the "mention on" links is created automatically for me.
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.