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.
- Create Confluence page
- ScriptRunner examples for Confluence Cloud
- ScriptRunner samples for Bitbucket, Bamboo, Confluence, and Jira
- Best practices for ScriptRunner behaviors for Jira
原文链接:Install Groovy with ZSH (plus automation in Jira & Confluence)
暂无评论内容