Jenkins执行 remote SSH 命令
1.安装 SSH Pipeline Steps 插件
2.在凭据中添加remote server凭据,如下
3.Pipeline编写:
def GetRemoteServer(ip){
def remote = [:]
remote.name = ip
remote.host = ip
remote.port = 22
remote.allowAnyHosts = true
//通过withCredentials调用Jenkins凭据中已保存的凭据,credentialsId需要填写,其他保持默认即可
withCredentials([usernamePassword(credentialsId: 'c0c1281-36df-4c5-b26d-dcf5208776f', passwordVariable: 'password', usernameVariable: 'userName')]) {
remote.user = "${userName}"
remote.password = "${password}"
}
return remote
}
pipeline{
agent any
stages{
stage("任务申请"){
steps{
script{
//调用上面定义好的方法
rserver = GetRemoteServer('10.10.2.11')
sshCommand remote: rserver, command: "ifconfig" //在remote server上执行ifconfig命令
}
}
}
}
}
}
方法二,不定义方法,直接使用:
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"
}
}
}
} }
}
Jenkins执行 remote SSH 命令的更多相关文章
- jenkins 执行远程linux命令
在Jenkins中进行构建时,可能需要首先SSH登录到一个远程服务器以执行必要的脚本,然后再执行构建.这时,需要安装SSH Plugin,并进行如下配置.1.在Jenkins界面,系统管理->管 ...
- Go执行远程ssh命令
使用包:golang.org/x/crypto/ssh 以下封装一个发送命令的Cli结构体 type Cli struct { IP string //IP地址 Username string //用 ...
- jenkins执行shell提示命令不存在
问题描述: jenkins编译项目,不继承linux环境变量 ~/.bash_profile ~/.bashrc /etc/profile,导致在执行shell脚本,提示命令找不到! [sz-hg ...
- 在Jenkins中配置执行远程shell命令
1.想要 远程登录到linux服务器并执行相应的shell脚本,需要在jenkins上安装插件enkins SSH plugin 2. 安装了这个插件后,进入系统的配置管理中配置 SSH remote ...
- jenkins(3): jenkins执行shell命令
参考: https://www.cnblogs.com/reblue520/p/7146693.html 1. 执行 本地 shell命令或者脚本 是在一个构建中的 bulid 选项卡. 执行本地中 ...
- ssh伪登陆执行远程主机脚本命令 C程序基于ssh passwordless执行远程主机命令及基于配置文件的验证伪登陆执行命令
1,基于有密码及免秘钥在远程主机上执行命令及脚本 ssh -T ip "CLI or shell.sh"; 2,C程序实现上述功能--基于password-less
- 【转】使用shell登录远程服务器执行多条命令,ssh登录之后执行脚本文件
原文:https://blog.csdn.net/qq_36622490/article/details/100773589 这个需求主要是我在jenkins中pipeline的代码里,需要使用she ...
- Jenkins: 执行 PowerShell 命令
Jenkins 默认是不支持执行 PowerShell 命令的,需要安装插件才能完成这样的任务.本文将介绍 Jenkins PoserShell 插件的基本用法和常见问题. 安装 PowerShell ...
- linux利用ssh远程执行多台机器执行同样的命令
这篇文章主要介绍了ssh远程执行命令方法和Shell脚本实例,本文讲解了ssh执行远程操作方法和远程执行命令shell脚本示例,需要的朋友可以参考下 ssh执行远程操作命令格式代码如下: ssh -t ...
随机推荐
- HTML 网页开发、CSS 基础语法——十一. CSS常用样式
文字三属性 1.颜色color 2.字体font-family ① 常用字体 常用的中文字体: 宋体 SimSum 微软雅黑 Microsoft YaHei 常用的英文字体: 如果不设置字体属性,不 ...
- 鸿蒙内核源码分析(消息队列篇) | 进程间如何异步传递大数据 | 百篇博客分析OpenHarmony源码 | v33.02
百篇博客系列篇.本篇为: v33.xx 鸿蒙内核源码分析(消息队列篇) | 进程间如何异步传递大数据 | 51.c.h .o 进程通讯相关篇为: v26.xx 鸿蒙内核源码分析(自旋锁篇) | 自旋锁 ...
- Cnblogs 主题设置
https://www.cnblogs.com/enjoy233/p/cnblogs-markdown-code-display-opt.html 复制: 右上角添加复制按钮:https://www. ...
- 获取classpath(src/main/resources)的绝对路径
先贴上代码 private static String basePath = Thread.currentThread().getContextClassLoader().getResource(&q ...
- NOIP 模拟 七十一
最后一场多校模拟赛,好像是信心赛??不过考的不行..最近难题比较多,对题目的难度把握不够好,经常出现简单题跳过的现象. 100+100+20+40 T1 签到题(qiandao) 如果一个点的度数不是 ...
- 为什么下一个十年的主战场在 Serverless?
作者 | 不瞋 阿里云 Serverless 负责人 "唯有超越,才能让我们走下去." 这是不瞋在阿里的第十年.从 2010 年加入阿里云,不瞋参与了阿里云飞天分布式系统的研发,历 ...
- 我们携手啦 | SphereEx 正式加入 openGauss 社区
近日,SphereEx 签署 CLA ( Contribution License Agreement,贡献许可协议),正式加入 openGauss 社区. SphereEx 和 openGauss ...
- 利用PATH环境变量 - 提升linux权限~👻
利用PATH提升linux权限 参考地址:https://www.hackingarticles.in/linux-privilege-escalation-using-path-variable/ ...
- WSL (Windows Subsystem for Linux)
WSL (Windows Subsystem for Linux) :适用于 Linux 的 Windows 子系统. References Install WSL with a single com ...
- 用C++实现的数独解题程序 SudokuSolver 2.4 及实例分析
SudokuSolver 2.4 程序实现 本次版本实现了 用C++实现的数独解题程序 SudokuSolver 2.3 及实例分析 里发现的第三个不完全收缩 grp 算法 thirdGreenWor ...