For post function confiuration

Naidu Lothugedda January 25, 2017

Hi 

Can anyone help me how to configure a post function in a workflow for execute a shell script

Thanks & regards

Naidu . l

 

1 answer

1 accepted

0 votes
Answer accepted
Stefan Arnold
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.
January 25, 2017
Naidu Lothugedda January 26, 2017

Hi Stefan Arnold 

         Thanks for your response, but what i am looking is,  I have a shell script in my local system and I want to execute it by using JIRA workflow (post function) please guide me how to configure it.

Thanks & regards

Naidu.l  

Stefan Arnold
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.
January 26, 2017

You cant do this directly from Jira.

As i said, with the JIRA Plugin ScriptRunner you can execute Scripts in the programming languange groovy in a workflow postfunction.

in this groovy script you can then execute a shell script that is on the same system as your JIRA.

For better explanation i have this little shell-script that simply creates a textfile with a message:

#!/bin/bash
 
echo "This is a Jira groovy to shell test" > /var/atlassian/application-data/jira/scripts/test.txt

 Now i want to execute this shell script from jira:

First, as already said, i need the "ScriptRunner"-Plugin to be able to execute "Groovy"-Scripts in Postfunctions.

i now have this groovy script:

def sout = new StringBuffer(), serr = new StringBuffer()
def proc = 'sh /var/atlassian/application-data/jira/scripts/testscript.sh'.exec$
proc.consumeProcessOutput(sout,serr)
proc.waitForOrKill(1000)
println sout

And in my workflow i add a postfunction to my transition thats execute the mentioned Groovy-Script:

groovyToShell.png

 

When i now execute the transition in the workflow it executes the groovy script which executes the shell-script and the textfile in my case is created.

 

I hope this helps!

Naidu Lothugedda January 26, 2017

Hi 

we are  select  the custom script runner option in post-function right ? please help me

 

Thanks and regards

Naidu 

 

Nic Brough -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.
January 31, 2017

If you pass the data you want to write to the shell script as a parameter, you can do whatever you want with it.

However, my "fix the actual problem" instincts are screaming here.  "I want to write data to a file" is a solution to some problem, but it feels like it's probably a very poor solution.

Could you tell us what this file is for?  There is a very strong chance that there is a *much* better way to meet your goal than writing data to a file.

Naidu Lothugedda January 31, 2017

Hi Nic 

I am not passing any parameters from a file, to storing issue details to specific destinations custom post-function options of using third party plugins (script runner) is it possible ?

Thanks & regards  

Nic Brough -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.
January 31, 2017

I don't know what that means.

You're trying to write data to a file  with a script (probably a very poor way to achieve your goals).  If you don't tell the script what you want to write, it can't write it.

Naidu Lothugedda January 31, 2017

I have create a issue in JIRA  with a specific workflow and i give the all details(status, priority,components, label,Affect version, fix-version ) to my issue. Now i want to print those details into a text file using groovy script 

I don't have any scripts. i am asking please share some scripts to store the issue details(type,priority, version) into a text file (/opt/text)  through my post function configuration (when the state changed to resolved then execute my script and store the issue details into a particular location ) 

i don't groovy please share some scripts

kind regards

Nic Brough -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.
February 1, 2017

Please, could you explain why you want to do this?

Also, you say you don't have any scripts, but the question was "how do I run a script".  Which is it?

Naidu Lothugedda February 1, 2017

Apologies , i have only

shell script

 

#!/bin/bash
  
echo "This is a Jira groovy to shell test" > /var/atlassian/application-data/jira/scripts/test.txt
groovy script
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = 'sh /var/atlassian/application-data/jira/scripts/testscript.sh'.execute ()
proc.consumeProcessOutput(sout,serr)
proc.waitForOrKill(1000)
println sout
Along with i need another script for print/store the issue details.
Why i am do this means I have store the all the binaries at one place by using the versions, this is the way  easy to deploy the binaries per a required version numbers 
please help me
 
Thanks & regards
Nic Brough -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.
February 1, 2017

>Why i am do this means I have store the all the binaries at one place by using the versions, this is the way  easy to deploy the binaries per a required version numbers

That's a terrible way to "store the binaries", if I understand what that means.  In fact, you don't need to do it at all, as all the information is in JIRA.

All you need to do to make your script work is add parameters.  In the "def proc" line Stefan gave you, add the text required as a parameter, then in your script start with "echo $1" to see it come out.

Naidu Lothugedda February 1, 2017

I am not understand what you said could you please explain briefly ?

Thanks & regards

Nic Brough -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.
February 1, 2017

I'm not sure I can explain it.  Modify the code Stefan gave you adding the parameters, then modify your shell script to do something with them.

Naidu Lothugedda February 1, 2017

I think you are saying , I have to give & declare the parameters in my shell script right ?

Thanks & regards

Nic Brough -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.
February 1, 2017

Nearly, although I think you really mean what I am about to say.

You need to give the script parameters when you call it, and then you can use the data passed into it in the script.

 

Naidu Lothugedda February 1, 2017

but i what to print my issue version details how do i get that ?

Thanks and regards

Nic Brough -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.
February 1, 2017

issue.getVersions() is a start.  I don't know what details you need from it.

Naidu Lothugedda February 1, 2017

ok , I used  issue.getVersions()  in  groovy script, Is it enough to get the version details of my issue

Nic Brough -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.
February 1, 2017

Probably not, as the result is a list of version objects.  You haven't said what details you actually want.

Naidu Lothugedda February 1, 2017

I want to print  what version is released with a particular issue  

Thanks & regards

Nic Brough -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.
February 1, 2017

How are you storing that?  How do you know which one is released?  An issue can have several versions which might be unreleased, released or even archived.

Naidu Lothugedda February 1, 2017

suppose , I have  to work on feature-1, then i  was create a issue(task/bug) in JIRA  and give the version detail like 1.0v (under affect version/fix version) right ? now i want to print the version details with in the same workflow  is it possible ? 

And one thing we have trigger to print the version details if the issue is in resolved state

Nic Brough -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.
February 1, 2017

I'm sorry, that still does not explain it.

Maybe if I knew what you were trying to achieve, I could get more from your explanations - some context often helps.  What are you trying to give to the end user?  Not how, but what should they see and why?

Naidu Lothugedda February 1, 2017

I not giving anything to end user, and they don't see any thing .

I am trying to automate the flow and we are able print those details it can easy our process

Nic Brough -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.
February 1, 2017

So imagine the "end user" is your automatic process - what should it be getting from JIRA and why?

Naidu Lothugedda February 1, 2017

Basically the end user is not involved in our automatic process and JIRA but in case they need work status then we send the report from JIRA

Thanks & regards

 

Nic Brough -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.
February 1, 2017

Could you please give me the context of what you are trying to do.  I cannot make head nor tail of your explanations without that context.  I don't care that it's an automation, I need to understand why you want to do this so I can understand what you are trying to get out of it.

Naidu Lothugedda February 1, 2017

I have maintain   a central repository to store all my binaries with a version number(what i was given in JIRA  issue) by manually but,

If we are able to print the issue properties/details then i can pass those value as a parameters to my next process 

so i want asking to you is there any approach to print those value.

Thanks and regards 

Nic Brough -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.
February 1, 2017

Ok, that's vague and doesn't tell us much more than you had before, but it's getting there.  Some more questions

  1. What are these binaries?  Not their content or type really, but can we assume a binary is just "a file I have"?
  2. Where are they coming from?
  3. Where are you wanting to store them?
  4. How do you want to use JIRA for this?  Not "I want to write a file", but in the UI or automation sense of what it is trying to do.  For example, are you using an issue to track a process like "My client has sent us a file, we need to store it in the repository". 
Naidu Lothugedda February 1, 2017

1.binaries means files like .war , ear .class.

2.from build/release team.

3.nexus repository.

4.see JIRA  is mainly used  for tacking and controlling  right, in my case also use for tacking and control .

could please tell me one thing suppose, we have create a issue(task/bug/store)in JIRA then what details we are provide ?

Thanks & regards

Nic Brough -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.
February 2, 2017

Ok, great, that explains most of it.  My question now is what the issues and versions have to do with your storage process?

As a side thought, why aren't your build/release team putting the binaries directly into Nexus?

Naidu Lothugedda February 2, 2017

Nexus is our binaries storage location why because, suppose we have released many versions(like 1.0,2.0,3.0..............................10.0) customer rise a bug on 5.0 then we can take the binaries(5.0) deploy it and easy to figure-out   solution right(Is it environment problem or something else) 

And I tried the following script for print the version of  issue using post function its woking fine

import com.atlassian.jira.issue.Issue
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.customisers.ContextBaseScript
@BaseScript ContextBaseScript script

Issue issue = getIssueOrDefault("")
def response = issue.getFixVersions()
// create a file
def file = new File('/var/atlassian/application-data/jira/scripts/response.txt');
// save the response to it
file << response

Thanks & regards

Suggest an answer

Log in or Sign up to answer