Triggering script on some acction?

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

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

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.

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

Steven Behnke Community Champion Aug 20, 2015

No problem

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 Behnke Community Champion Aug 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.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published 6 hours ago in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

27 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you