Groovy SSH is an automation tool based on DSL providing the remote command execution and file transfer.
Here is an example script for the typical deployment scenario.
// deploy.groovy
ssh.remotes {
webServer {
host = '192.168.1.101'
user = 'jenkins'
identity = new File('id_rsa')
}
}
ssh.run {
session(ssh.remotes.webServer) {
put from: 'example.war', into: '/webapps'
execute 'sudo service tomcat restart'
}
}See document of Gradle SSH Plugin for details of DSL.
We have following methods to run the script.
Install gssh from Homebrew and run the script.
brew install gssh
gssh deploy.groovyDownload the latest gssh.jar from releases and run the script.
java -jar gssh.jar deploy.groovyAdd following header to the script for using Grape,
@Grab('org.hidetake:groovy-ssh:x.y.z')
@Grab('ch.qos.logback:logback-classic:1.1.2')
def ssh = org.hidetake.groovy.ssh.Ssh.newService()and run the script on Groovy.
groovy deploy.groovyWe can embed Groovy SSH library in the Groovy application.
The library is available on Maven Central and Bintray.
// Gradle
compile 'org.hidetake:groovy-ssh:x.y.z'Instantiate a Service
by Ssh#newService()
and run the script as follows.
import org.hidetake.groovy.ssh.Ssh
def ssh = Ssh.newService()
ssh.remotes {
webServer {
host = '192.168.1.101'
user = 'jenkins'
identity = new File('id_rsa')
}
}
ssh.run {
session(ssh.remotes.webServer) {
put from: 'example.war', into: '/webapps'
execute 'sudo service tomcat restart'
}
}This is an open source software licensed under the Apache License Version 2.0. Feel free to open issues or pull requests.