Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira version macro in Confluence page

Arunkumar Duraimani December 25, 2023

Hi,

My requirement is to create a macro in confluence using script-runner to get the jira version. I am getting getting error while executing the below script in script-runner console page in confluence.

unable to resolve class com.atlassian.sal.api.net.RequestFactory
unable to resolve class com.atlassian.jira.component.ComponentAccessor

import groovy.json.JsonSlurper
import com.atlassian.sal.api.net.RequestFactory
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.BuildUtilsInfo


def jiraBaseUrl = "https://server-hostname"
def jiraApiPath = "/rest/api/2/serverInfo"

/*def requestfact = new RequestFactory()
def response = requestfact.createRequest()
.setMethod("GET")
.setUrl("${jiraBaseUrl}${jiraApiPath}")
.execute()

// Parse the response JSON
def jsonResponse = new JsonSlurper().parseText(response.getResponseBodyAsString()) */

 def jiraVersion = jsonResponse.version
def jiraBuildNo = jsonResponse.buildNumber
def jiraBuildDate = jsonResponse.buildDate
log.info("Jira Version: ${jiraVersion}")
log.info("Jira BuildNo: ${jiraBuildNo}")
log.info("Jira BuildDate: ${jiraBuildDate}")

 

Thanks

Arun

2 answers

2 accepted

1 vote
Answer accepted
Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 25, 2023

Hi @Arunkumar Duraimani welcome to the community.  As mentioned it would help a great deal to finding a solution if we know the error.  Please provide the error message that you are getting.

Arunkumar Duraimani December 25, 2023

Hi Craig,

I am getting the below error.

unable to resolve class com.atlassian.sal.api.net.RequestFactory
at line: 2, column: 1

unable to resolve class com.atlassian.jira.component.ComponentAccessor
at line: 3, column: 1

unable to resolve class com.atlassian.jira.util.BuildUtilsInfo

thanks

Arunkumar.

0 votes
Answer accepted
Nic Brough -Adaptavist-
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.
December 25, 2023

Welcome to the Atlassian Community!

What error are you getting?

Arunkumar Duraimani December 25, 2023

Hi Nic,

I am getting the below error.

unable to resolve class com.atlassian.sal.api.net.RequestFactory
at line: 2, column: 1

unable to resolve class com.atlassian.jira.component.ComponentAccessor
at line: 3, column: 1

unable to resolve class com.atlassian.jira.util.BuildUtilsInfo

thanks

Arunkumar.

Nic Brough -Adaptavist-
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.
December 26, 2023

Confluence does not have those classes in it.  You need to be coding for Confluence to make REST calls, not Jira.

Arunkumar Duraimani December 26, 2023

Hi Nic,

Can i check the confluence java api to fetch the jira version.

 

Thanks

Arunkumar.

Nic Brough -Adaptavist-
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.
December 28, 2023

This is not going to work.  You cannot "fetch the Jira version".

I do not think you understand quite what the structure here is.  Jira and Confluence are separate systems, and have very different APIs because they do different things.  Jira's API works primarily with issues, Confluence with pages.

Confluence does not have an API for working with issues and Jira does not have an API for working with pages.

What you've got is a load of imports for Jira, followed by some code that (at a glance) is system-agnostic - you could run it from anything and it would try to read Jira's REST data into the variables. 

All you need to import are the classes required to support REST calls.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, dance, gamification, badge, razzle dazzle, team '25 anaheim

Earn a one-day badge today and do the Atlazzle Dazzle! 🕺

Today only! Share what you’re the most excited about for Team ‘25 or just dance out the beginning of a new quarter with us.

Comment the post
AUG Leaders

Atlassian Community Events