In this page
Running a shell script on Linux when a commit is accepted
This automation runs an external Linux shell script (.sh), optionally parsing parameters from the VCS commit message and passing those to the script.
The shell script process is started by a short Groovy script.
Configuration
- Login to Jira as admin, go to Administration → System → Automation rules.
- Click Create rule.
- Select the trigger Genius Commit created (from the DevOps category).
- Choose the command Run code, and click Save.
- Click New action.
- Select the action Run Groovy script.
- Enter a one-line description in the Summary field.
- Enter the script code in the Script field.
-
If you use are using a command configured with a parameter pattern and the parameter arg was successfully parsed, you can access its value using this expression:
## use the parameter's name in the suffix (last item) def x = devops.arg
- To access smart values, use this syntax. (The {{...}} syntax doesn't work in Groovy scripts.)
-
If you use are using a command configured with a parameter pattern and the parameter arg was successfully parsed, you can access its value using this expression:
- Click Save.
- Name your automation rule intuitively, and click Turn it on.
Usage
-
Enter this inline Groovy script in your automation action:
def cmd = "/my/directory/test.sh ${devops.arg}" def out = new StringBuilder(), err = new StringBuilder() def proc = cmd.execute() proc.consumeProcessOutput(out, err) proc.waitForOrKill(1000) if (out) { auditLog.info(out) } if (err) { auditLog.error(err) }
It starts the shell script process passing the parameter value as argument, waits for its completion, then writes the process' standard output and standard error to the automation action's audit log. -
Create test.sh with the following content:
echo "Shell script started with the argument: $1"
(It just writes a line to the standard output and demonstrates how to access the parameter value received as argument.) -
Create a commit with this commit message:
Fix the FOO-1 bug. @run foobar
- The shell script will be run with the parameter passed to it.
-
The following message will appear in the automation action's audit log:
Shell script started with the argument: foobar
Troubleshooting
If you don't get the expected results:
- Check if the @run command is defined in the Genius Commands screen? (It's a default command.)
- Check if the @run command followed by the command parameter was included in the commit message?
- See the general troubleshooting steps.
Questions?
Ask us any time.