jenkins远程执行remote ssh命令

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.csdn.net/weixin_38418878/article/details/90438649

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值