Skip to content

Instantly share code, notes, and snippets.

@int128
Last active August 29, 2015 14:05
Show Gist options
  • Save int128/4a47631f55e7e2efeb78 to your computer and use it in GitHub Desktop.
Save int128/4a47631f55e7e2efeb78 to your computer and use it in GitHub Desktop.
Specification of Gradle SSH Plugin and Groovy SSH Library (work in progress)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.hidetake:gradle-ssh-plugin:0.4.0'
}
}
apply plugin: 'ssh'
// Global settings
ssh.settings {
identity = file('id_rsa') // Enable public key authentication
knownHosts = allowAnyHosts // Disable host key verification
}
// Add a remote host
ssh.remotes {
webServer {
host = '192.168.1.101'
user = 'jenkins'
}
}
task deploy(dependsOn: war) << {
ssh.run {
settings {
// Enable PTY allocation for sudo
pty = true
}
session(ssh.remotes.webServer) {
// Put a built WAR to the server
put war.archivePath, '/webapps'
// Restart the application server
execute 'sudo service tomcat restart'
}
}
}
@Grab(group='org.hidetake', module='groovy-ssh', version='0.1.0')
import static org.hidetake.groovy.ssh.Ssh.*
// Global settings
ssh.settings {
identity = new File('id_rsa') // Enable public key authentication
knownHosts = allowAnyHosts // Disable host key verification
}
// Add a remote host
ssh.remotes {
webServer {
host = '192.168.1.101'
user = 'jenkins'
}
}
ssh.run {
settings {
// Enable PTY allocation for sudo
pty = true
}
session(ssh.remotes.webServer) {
// Put a built WAR to the server
put 'example.war', '/webapps'
// Restart the application server
execute 'sudo service tomcat restart'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment