Example code for jira scripting

Hi,

I’m looking for a working example code for a Jira request (e.g. create new issue) using the “Jira Scripting API” macro.

I’ve installed the “Jira Macro” and “Jira Administration” and they both work. - At least I can display processes using the Jira macro.

However, since we also want to create processes from xwiki, “Jira Scripting” would be ideal - especially since the creation is done with a dedicated user and the authentication data should not be displayed to the user.

Has anyone ever managed this successfully?

Unfortunately, the example code on the macro page (https://extensions.xwiki.org/xwiki/bin/view/Extension/JIRA+Module) only creates an empty table.

Thanks and best regards,
brunt

Hi,

I’ve been playing around a bit with the groovy and velocity examples and it seems that the “NullProgressMonitor” class is no longer available in the JIRA REST Client library.

Therefore, I left out the ProgressMonitor and got the following code snippets:

{{groovy}}
import com.atlassian.jira.rest.client.*
import org.xwiki.contrib.jira.config.*

def client = services.get(“jira”).getJiraRestClient(new JIRAServer(“https://jira.domain.com/”))
def promise = client.getIssueClient().getIssue(“SMW-57”)
def issue = promise.claim()

println “Summary: ${issue.getSummary()}”
{{/groovy}}

{{velocity}}
#set ($client = $services.jira.getJiraRestClient(“jira”))
#set ($issue = $client.getIssueClient().getIssue(“SMW-57”).claim())

Summary: $issue.summary
{{/velocity}}

{{jira id=“jira”}}
SMW-57
{{/jira}}

While the velocity code and the Jira macro provide a valid output, I get a 401 message from the Groovy code.

Any idea why?

Thanks und regards,
brunt

I assumed that the user name and password would be taken from the defined Jira instance (see https://extensions.xwiki.org/xwiki/bin/view/Extension/JIRA%20Administration/). However, this is obviously not the case with the Jira Scripting API, only with the “Jira Macro”.

The correct code would therefore look like this:

def client = services.get(“jira”).getJiraRestClient(new JIRAServer(“${jiraURL}”, “${jiraUser}”, “${jiraPwd}”))

The variables must of course be filled accordingly.