Let me share with you my experience with creating an additional, own web page in the Jira Server instance which based on data derived from the issue. Sometimes we need to create some individual page contains tables, list or something else which based on the Jira data. Of course, we could create our own plugin using the Atlassian SDK, but if we have installed the ScriptRunner plugin, we can do it quite fast and easy.
1. We have to create a simple REST Endpoint to generate our own site (Mange Apps -> Script Runner -> REST Endpoints). I have add some comments to show how it works.
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import javax.servlet.http.HttpServletRequest
import com.atlassian.webresource.api.UrlMode
import com.atlassian.webresource.api.assembler.PageBuilderService
import com.atlassian.webresource.api.assembler.WebResourceAssembler
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
simplePage(httpMethod: "GET") { MultivaluedMap queryParams, body, HttpServletRequest request ->
PageBuilderService pageBuilderService = ComponentAccessor.getComponentOfType(PageBuilderService);
WebResourceAssembler assembler = pageBuilderService.assembler();
// Web resources from the our Jira Instance, e.g JQuery
List<String> requiredResources = ["jira.webresources:jquery","jira.webresources:global-static"];
requiredResources.each {
String moduleKey ->
assembler.resources().requireWebResource(moduleKey);
}
// #### You can get some necessary data from the current issue, e.g.
// 1. BaseUrl
def baseurl = ComponentAccessor.getApplicationProperties().getString().getString("jira.baseurl");
// 2. Data from the current issue, if you use a custom web item and define a link with parameters:
// e.g. <endpointURL>?issueId=${issue.key}
def issueId = queryParams.getFirst("issueId") as String; // get an id from the URL get parameter
def issue = ComponentAccessor.getIssueManager().getIssueObject(issueId); // now you can get an issue object
Writer sw = new StringWriter()
sw << """
<html>
<head>
<title>My simple page</title>""";
pageBuilderService.assembler().assembled().drainIncludedResources().writeHtmlTags(sw, UrlMode.AUTO)
sw << """
</head>
<!-- We can use style classes from our Jira instance -->
<body id="jira" class="aui-layout aui-theme-default">
<!-- We can include data from selected issue -->
<h1>My issue summary is: """ + issue.getSummary() + """</h1>
</body>
</html>
""";
Response.ok().type(MediaType.TEXT_HTML).entity(sw.toString()).build()
}
2. If we already have a REST Endpoint created we could use it to add Web Item, e.g. button (Manage Apps -> ScriptRunner -> Fragments). If we would like to show this button on the issue view screen we could select section jira.issue.tools, set Navigate to a link and add URL address to our REST Endpoint includes GET Parameter/s, e.g <endpoint_address>?issueId=${issue.key}.