DEV Community

Alyss ๐Ÿ’œ
Alyss ๐Ÿ’œ

Posted on

Install Groovy with ZSH (plus automation in Jira & Confluence)

Full disclosure: I work for Atlassian. As a result, I spend a great deal of time creating, updating, and reading Confluence pages. While Confluence server and cloud both have APIs which can be used to programmatically update/create pages, Adaptavist created an app called ScriptRunner which makes this easier with built-in scripts and pre-written logic. My end-goal is to automate some common, reoccuring tasks either by checking a Jira issue for updates or another confluence page. Most Atlassian applications are written in Java and ScriptRunner uses a flavor of Java called Groovy.

Step 1: install Groovy on OS X

For Homebrew users:

brew install groovy
Enter fullscreen mode Exit fullscreen mode

For MacPorts users:

sudo port install groovy
Enter fullscreen mode Exit fullscreen mode

Step 2: Set Groovy_home environment variable

You are welcome to do this entirely in zsh, but I manually added it to my ~/.zshrc file. Another note is I have Sublime set up to launch from the command line. If you prefer vim, emacs, or another text editor, you will need to substitute references to subl.

subl ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Within ~/.zshrc, I'm adding the following variable export and comment:

# Add Groovy Home path
export GROOVY_HOME="$(/usr/local/opt/groovy/libexec)"
Enter fullscreen mode Exit fullscreen mode

Save this file, then you can close it once you're done.

Step 3: Run a test to check your Groovy install

mkdir groovy-test && cd groovy-test
subl hello.groovy
Enter fullscreen mode Exit fullscreen mode

Now, add a test script to the empty file you just created:

//hello.groovy
println "hello, world"
for (arg in this.args ) {
    println "Argument:" + arg;
}
// this is a comment
/* a block comment, commenting out an alternative to above:
this.args.each{ arg -> println "hello, ${arg}"}
*/
Enter fullscreen mode Exit fullscreen mode

Save this file, then you can close it once you're done.

Run it with the following:

groovy hello.groovy MyName yourName HisName
Enter fullscreen mode Exit fullscreen mode

Step 4: Start using Groovy to automate tasks in Jira or Confluence

As I mentioned before, Adaptavist offers some built-in scripts but I find my needs are more complex. There are some good examples floating around the web to help get started.

Top comments (4)

Collapse
 
shostarsson profile image
Rรฉmi Lavedrine

Thanks, I would love to know more about what we can do to automate things on Bitbucket.
I cliked on the link you provided but didn't find anything relevant.

Great article anyway.

Collapse
 
preciselyalyss profile image
Alyss ๐Ÿ’œ

Are you using Bitbucket Server or Bitbucket.org?

Collapse
 
shostarsson profile image
Rรฉmi Lavedrine

Bitbucket.org

Thread Thread
 
preciselyalyss profile image
Alyss ๐Ÿ’œ

ScriptRunner is only on Bitbucket Server (to my knowledge). In June, Bitbucket.org released a v2 API and documented with Swagger/OAS 2.0. I've used OAS in the past to generate code samples via Postman.