我一直在尝试通过传递脚本
sshScript remote:remote
两个参数myscript.sh
和\\abc
来通过xyz
在远程系统中执行脚本,如下所示:
sshScript remote: remote, script: "myscript.sh \\abc xyz"
Jenkins 失败,显示“
myscript.sh \abc xyz
不存在”。为了测试,您可以尝试使用
bash -c '...'
: 强制将脚本视为命令的一部分
def remote = [:]
remote.name = 'test'
remote.host = 'test.domain.com'
remote.user = 'root'
remote.password = 'password'
remote.allowAnyHosts = true
stage('Remote SSH') {
sshCommand remote: remote, command: "bash -c 'myscript.sh \\abc xyz'"
}
OP T M Suhas在评论中添加了:
位于Jenkins工作区(本地系统)中,我想避免将Myscript.sh
上传到远程系统然后执行它。myscript.sh
那么需要先
scp
到远程服务器,然后才能执行。
您无法使用 sshScript 传递参数。该插件不支持它。您可以使用 writeFile 选项
writeFile file: 'script.sh', text: """#!/bin/bash myscript.sh \\abc xyz"""
然后使用ssh脚本
sshScript remote: remote, script: 'script.sh'
这将使用文本中编写的脚本。
或者您可以使用 sshCommand 代替。