jenkins远程执行remote ssh命令
ssh remote
首先安装SSH pipeline steps 插件
大概分为以下几种
1. 在凭据中添加remote server凭据,
//通过withCredentials调用Jenkins凭据中已保存的凭据,credentialsId需要填写,其他保持默认即可
withCredentials([usernamePassword(credentialsId: 'c0c1281-36df-4c5-b26d-dcf5208776f', passwordVariable: 'password', usernameVariable: 'userName')])
{
remote.user = "${userName}"
remote.password = "${password}"
}
2.添加远程服务器到节点配置管理
pipeline任务通过agent node 制定到该节点 执行相关命令
3.不定义方法,直接使用
def remote = [:]
remote.name = 'saltm'
remote.host = '10.10.2.11'
remote.user = 'root'
remote.password = '1qjRg'
remote.allowAnyHosts = true
pipeline{
agent any
stages{
stage("任务申请"){
steps{
script{
sshCommand remote: remote, command: "ifconfig |grep inet"
}
}
}
}
}
}
参考博客:
https://www.cnblogs.com/dreamer-fish/p/13524138.html
https://blog.youkuaiyun.com/weixin_38418878/article/details/90438649