Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Call rest api on post function and get 502 error

Hi all,

I have two instances of Jira Server and need integrate them. I've made a groovy script and add it to post function on issue creation step. This script sends rest requests to another Jira to make issue there. But sometimes another Jira has performance issues and answers with 502 error. Problems can last for several minutes (sometimes more). How can I handle this case? Is it a good idea to add a loop to send a request until I get a 200 response? I'm afraid that in this case issue won't be created in first Jira instance for a long time if another instance having problems for a long time

Or may be I can make not a post function script but Listener which listens issue created event and add a loop to send a request until I get a 200 response there? 

 

2 answers

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

It's a custom post-function on transition.  Script just create new issue in another instance of Jira if some conditions true 

I need to add code only in one instance

And on issue transition fires my script which send request from instance 1 to instance 2 and if in this time instance 2 slows down issue in instance 2 not created. Is it good idea to loop sending request in instance 1 while instance 2 not stops slowing down 

String jkIssueKey = createIssueInJiraJK()

if (jkIssueKey != null){

    commentIssues(jkIssueKey)        

} else{

   log.warn("Issue not created, comment not added")

}

log.info("End of script")
def createIssueInJiraJK(){    

    def jkIssueKey = null

    def currentIssue = issue.key

    def createdIssueKey

    def addressJira = "https://jira.anotherinstance.net"

    def user = ''

    def password = ''

    def authString = "${user}:${password}".bytes.encodeBase64().toString()

    def timeout = 120000

    def defaultRequestConfig = RequestConfig.custom()

                            .setConnectionRequestTimeout(timeout)

                            .setConnectTimeout(timeout)

                            .setSocketTimeout(timeout)

                            .build()                

    def http = new HTTPBuilder("${addressJira}/rest/api/2/issue")

    http.ignoreSSLIssues();

    http.setClient(HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build())

    try {

        http.request(POST, ContentType.JSON) {

            headers.'Authorization' = "Basic ${authString}"

            body = ["fields":[

                    "project":[

                            "id":"100"

                 ],

                "summary":"${value_currentSummary}.toString(),

                "issuetype":[

                            "id":"11"

                ],

                "priority": [

                            "id": "2"

                ],           

                "description":"Description".toString()

                ]

            ]

            requestContentType = ContentType.JSON

                response.success = { resp, json ->  

                    jkIssueKey = json.key

                    log.info("Issue ${jkIssueKey} was created")

                    return jkIssueKey

                }

                response.failure = { resp ->

                    log.warn("response code is: " + resp.status.toString())        

                }

       }

} catch (Exception e) {

    log.warn("Exception : " + e)

}

}
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 28, 2023

Hi @aas

In your description, you mentioned:-

I have two instances of Jira Server and need integrate them. I've made a groovy script and add it to post function on issue creation step.

Are you adding the code in both instances with the required modifications?

Please share your Post-Function code so I can review it and suggest a better solution.

Also, please clarify what Post-Function you use to make the REST request. Is it the ScriptRunner Custom post-function?

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

I accidentally answered in the wrong place. Look my answer above please

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events