How to make ssh connection in workflow through groovy script by using sand box in Jenkins? -
how make ssh connection in workflow through groovy script using sand box in jenkins? need make ssh connection server , run particular script on server particular user id..
is there way that?
i had similar requirement our build system, , started this ssh.gradle task.
it comes down using ant's sshexec follows:
class sshtask extends defaulttask { // various properties host etc @input @optional string host @input @optional string username @input @optional string password @input @optional string keyfile @input @optional string passphrase private static boolean antinited = false sshtask() { if (!antinited) { antinited = true initant() } } protected initant() { project.configurations { sshanttask } project.dependencies { sshanttask "org.apache.ant:ant-jsch:1.8.2" } ant.taskdef(name: 'sshexec', classname: 'org.apache.tools.ant.taskdefs.optional.ssh.sshexec', classpath: project.configurations.sshanttask.aspath, loaderref: 'ssh') } def ssh(object... commandline) { def outputantproperty = "sshoutput-" + system.currenttimemillis() if (keyfile != null) { ant.sshexec(host: host, username: username, keyfile: keyfile, passphrase: passphrase, command: commandline.join(' '), outputproperty: "$outputantproperty") } else if (password != null) { ant.sshexec(host: host, username: username, password: password, command: commandline.join(' '), outputproperty: "$outputantproperty") } else { throw new gradleexception("one of password or keyfile must set perform ssh command") } def sshoutput = ant.project.properties."$outputantproperty" project.logger.lifecycle sshoutput } }
Comments
Post a Comment