Triggering script on some acction?

dali tom August 20, 2015

Hi all,

I am trying to work on some automation,  where if manager approves some request, I want to call script which ssh to some servers and execute commands and paste output in comments section.

 

Thanks in advance !!!

4 answers

1 vote
Steve Behnke [DiscoverEquip.com]
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.
August 20, 2015

The Script Runner add-on adds a Script Post-Function that you can utilize.

Inside a Workflow, there are Statuses like YellowIn Progress or Greenclosed. We can perform a sort of action when we are on a Status, like move from In Progress TO Closed, or perhaps move from In Progress to In Progress. These actions are called Transitions. On a Transition, we can add constraints or checks of sorts. We can also perform actions. These are called Conditions, Validators, and Post-Functions.

A Post-Function fires AFTER a Transition has occurred. This implies our logic should be determined in the Conditions and Validators, and our Script Post-Function should only be performing as simple of an action as possible. For instance: We should add a Condition to the Transition, so that only Manager can utilize the Approve Request. We should not utilize our Script for this.

To SSH, we can ssh using a script like so:

"ssh domain.com CustomShellScript.sh".execute()

 

This doesn't solve the request to paste output in the comments section. I don't believe we should be relying on a post-function to do this. Your remote script should reach out to JIRA via the REST API to add a comment itself. 

curl -D- -u user:user -X POST --data { "body": "This is a comment regarding the quality of the response." } -H "Content-Type: application/json" http://example:8080/rest/api/2/issue/EX-50/comment

https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-add-comment

0 votes
dali tom August 20, 2015

So idea for this automation is:

Engineer creates a ticket, put one or multiple strings and submit. Ticket goes for approval and ones it gets approved the script kicks off. The script should take that string from the ticket, ssh to server, execute that string and paste output to comment section.

Any idea how to tell my script to grab strings from the ticket? If I figure out how to tell my script to do that everything else should be easy after that.

 

Steven F Behnke
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.
August 20, 2015

Have you considered Webhooks (https://confluence.atlassian.com/display/JIRA/Managing+Webhooks)? You can use a "post-function webhook" to fire a Webhook to a URL, which would include issue details. Then your script could lift them from the JSON payload instead of having a Script Runner script try and pass the issue details. Perhaps this would be a more straight-forward implementation.

0 votes
dali tom August 20, 2015

Thank you so much guys for quick turnaround.. I really appreciate it.

Steven F Behnke
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.
August 20, 2015

No problem

0 votes
GabrielleJ
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.
August 20, 2015

Yes you can. What you can do is create a transition in your issue called "Approve" then for this transition, add a post-function called "Script Post-Function" on which you will need to supply the path of your script. 

The callback is tricky but I have the same requirements before. So what I did was I pass the JIRA issue number in the script which do some work and afterwards update that issue number with a separate JIRA API call.

Azeus System Team October 5, 2018

"So what I did was I pass the JIRA issue number in the script which do some work and afterwards update that issue number with a separate JIRA API call."

May I know how you did this? I also need to trigger a script through a transition but that script needs the details of the specific issue that triggered it. I still can't figure out how to do that part.

Thank you.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events