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 ...
随机推荐
- P5782-[POI2001]和平委员会【2-SAT】
正题 题目链接:https://www.luogu.com.cn/problem/P5782 题目大意 \(n\)对人,每对之间恰好有一个人出席.\(m\)对仇恨关系表示两个人不能同时出席. 求是否有 ...
- Phalcon如何创建多模块并能进行访问 《Phalcon入坑指南系列 四》
本系列目录 一.Phalcon在Windows上安装 <Phalcon入坑指南系列 一> 二.Phalcon入坑必须知道的功能<Phalcon入坑指南系列 二> 三.Phalc ...
- Unittest 框架之断言,你学会了吗??
unittest断言 Python在 unittest.TestCase 类中提供了很多断言方法.断言方法检查你认为应该满足的条件是否确实满足.如果该条件确实满足,你对程序行为的假设就得到了确认,你就 ...
- Hibernate 的 <= 出现问题
问题模拟 select new map( e.name as name , e.salary as salary) from Emplpyee e where e.salary <= :sala ...
- T-SQL——透视PIVOT动态获取待扩展元素集
目录 0.背景说明 1.准备测试数据 2.示例1--利用SELECT循环赋值 3.示例2--使用游标 4.示例3--使用FOR XML PATH() 5. 参考 志铭-2021年10月8日 00:57 ...
- 数据库MHA原理
一.数据库的高可用MHA (1):详细的步骤 1.master mysql宕机了,MHA manager :无法连接master 2.MHA在S1 S2找一个延迟最小的slave,确定为未来的mast ...
- Java(31)泛型和可变参数
作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15228443.html 博客主页:https://www.cnblogs.com/testero ...
- vue2和vue3比较
一.vue3新特性: 1.数据响应重新实现(ES6的proxy代替Es5的Object.defineProperty) 2.源码使用ts重写,更好的类型推导 3.虚拟DOM新算法(更快,更小) 4.提 ...
- 原生js-无缝滚动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【UE4 C++】读写Text文件 FFileHelper
CoreMisc.h 读取 FFileHelper::LoadFileToString 读取全部内容,存到 FString FString TextPath = FPaths::ProjectDir( ...