Skip to content

Instantly share code, notes, and snippets.

@kiy0taka
Created October 23, 2009 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiy0taka/216943 to your computer and use it in GitHub Desktop.
Save kiy0taka/216943 to your computer and use it in GitHub Desktop.
[Groovy] Install and setup Grails to Hudson
import hudson.*
import hudson.model.*
/*
1. Download Hudson.
wget -O hudson.war http://hudson-ci.org/latest/hudson.war
2. Run Hudson.
java -jar hudson.war &
3. Download hudson-cli.jar
wget -O hudson-cli.jar http://yourserver/jnlpJars/hudson-cli.jar
4. Run this script with Hudson CLI.
java -jar hudson-cli.jar http://yourserver/hudson groovy GrailsInstaller.groovy
5. Restart Hudson.
kill %1
java -jar hudson.war &
*/
def listGrails = {
('http://dist.codehaus.org/grails/'.toURL().text =~ /href="(grails-.*?\.zip?)"/)
.collect{ it[1] }
.findAll{ !(it =~ /src|doc/) }
.collect{ [version:it - ~/grails-(bin-)?/ - '.zip', name:it] }
.sort{ it.version }
}
args = args ?: ['help']
([
install : { version ->
File.metaClass.plus = { String c -> new File(delegate, c) }
def grailsList = listGrails()
def grails = version ? grailsList.find{ it.version == version } : grailsList[-1]
assert grails, "No available Grails. Version [${version}]"
def fileName = grails.name
def rootDir = Hudson.instance.rootDir
// Install Grails Plugin
println "Downloading Grails Plugin."
rootDir + 'plugins/grails.hpi' << 'http://hudson-ci.org/download/plugins/grails/1.0.5/grails.hpi'.toURL().openStream()
// Install Grails
def toolsDir = rootDir + 'tools'
toolsDir.mkdir()
println "Downloading Grails [${grails.version}]"
new FilePath(toolsDir).unzipFrom("http://dist.codehaus.org/grails/$fileName".toURL().openStream())
def destDir = toolsDir + (fileName - 'bin-' - '.zip')
new FilePath(destDir).list('**/*').each { it.chmod(0755) }
// Configure Grails Builder
rootDir + 'com.g2one.hudson.grails.GrailsBuilder.xml' << """<?xml version='1.0' encoding='UTF-8'?>
<com.g2one.hudson.grails.GrailsBuilder_-DescriptorImpl>
<installations>
<com.g2one.hudson.grails.GrailsInstallation>
<name>${destDir.name}</name>
<grailsHome>${destDir.absolutePath}</grailsHome>
</com.g2one.hudson.grails.GrailsInstallation>
</installations>
</com.g2one.hudson.grails.GrailsBuilder_-DescriptorImpl>"""
println "Complete!\nPlease restart Hudson."
},
'list' : {
listGrails().each{ println it.version }
},
'jggug' : {
println 'http://www.jggug.org/'
},
'help': {
println """Usage: command [args...]
where commands include:
install [grails-version] install and setup Grails to Hudson
list print all Grails versions
help print this help message
jggug Japan Grails/Groovy User Group"""
}
][args[0]] ?: { println "command not found. '${args[0]}'" })(args.size() >= 2 ? args[1] : null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment