如何在 Jenkins 中使用沙箱通过 groovy 脚本在工作流中建立 ssh 连接?
How to make ssh connection in workflow through groovy script by using sand box in Jenkins?
如何在 Jenkins 中使用沙盒通过 groovy 脚本在工作流中建立 ssh 连接?
我们需要建立一个到服务器的 ssh 连接和 运行 该服务器上具有特定用户 ID 的特定脚本..
有什么办法吗?
我对构建系统有类似的要求,我从 this ssh.gradle task 开始。
归结为使用ant的sshexec如下:
class SshTask extends DefaultTask {
// various properties for the 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 be set to perform ssh command")
}
def sshoutput = ant.project.properties."$outputAntProperty"
project.logger.lifecycle sshoutput
}
}
没有技巧。
sh 'ssh -u someone server some-script'
如何在 Jenkins 中使用沙盒通过 groovy 脚本在工作流中建立 ssh 连接? 我们需要建立一个到服务器的 ssh 连接和 运行 该服务器上具有特定用户 ID 的特定脚本..
有什么办法吗?
我对构建系统有类似的要求,我从 this ssh.gradle task 开始。
归结为使用ant的sshexec如下:
class SshTask extends DefaultTask {
// various properties for the 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 be set to perform ssh command")
}
def sshoutput = ant.project.properties."$outputAntProperty"
project.logger.lifecycle sshoutput
}
}
没有技巧。
sh 'ssh -u someone server some-script'