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
For MacPorts users:
sudo port install groovy
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
Within ~/.zshrc
, I'm adding the following variable export and comment:
# Add Groovy Home path
export GROOVY_HOME="$(/usr/local/opt/groovy/libexec)"
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
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}"}
*/
Save this file, then you can close it once you're done.
Run it with the following:
groovy hello.groovy MyName yourName HisName
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)
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.
Are you using Bitbucket Server or Bitbucket.org?
Bitbucket.org
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.