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 命令的更多相关文章

  1. jenkins 执行远程linux命令

    在Jenkins中进行构建时,可能需要首先SSH登录到一个远程服务器以执行必要的脚本,然后再执行构建.这时,需要安装SSH Plugin,并进行如下配置.1.在Jenkins界面,系统管理->管 ...

  2. Go执行远程ssh命令

    使用包:golang.org/x/crypto/ssh 以下封装一个发送命令的Cli结构体 type Cli struct { IP string //IP地址 Username string //用 ...

  3. jenkins执行shell提示命令不存在

    问题描述: jenkins编译项目,不继承linux环境变量 ~/.bash_profile  ~/.bashrc  /etc/profile,导致在执行shell脚本,提示命令找不到! [sz-hg ...

  4. 在Jenkins中配置执行远程shell命令

    1.想要 远程登录到linux服务器并执行相应的shell脚本,需要在jenkins上安装插件enkins SSH plugin 2. 安装了这个插件后,进入系统的配置管理中配置 SSH remote ...

  5. jenkins(3): jenkins执行shell命令

    参考: https://www.cnblogs.com/reblue520/p/7146693.html 1. 执行 本地 shell命令或者脚本 是在一个构建中的  bulid 选项卡. 执行本地中 ...

  6. ssh伪登陆执行远程主机脚本命令 C程序基于ssh passwordless执行远程主机命令及基于配置文件的验证伪登陆执行命令

    1,基于有密码及免秘钥在远程主机上执行命令及脚本 ssh -T ip "CLI or shell.sh"; 2,C程序实现上述功能--基于password-less

  7. 【转】使用shell登录远程服务器执行多条命令,ssh登录之后执行脚本文件

    原文:https://blog.csdn.net/qq_36622490/article/details/100773589 这个需求主要是我在jenkins中pipeline的代码里,需要使用she ...

  8. Jenkins: 执行 PowerShell 命令

    Jenkins 默认是不支持执行 PowerShell 命令的,需要安装插件才能完成这样的任务.本文将介绍 Jenkins PoserShell 插件的基本用法和常见问题. 安装 PowerShell ...

  9. linux利用ssh远程执行多台机器执行同样的命令

    这篇文章主要介绍了ssh远程执行命令方法和Shell脚本实例,本文讲解了ssh执行远程操作方法和远程执行命令shell脚本示例,需要的朋友可以参考下 ssh执行远程操作命令格式代码如下: ssh -t ...

随机推荐

  1. iGuard6.0 — 各适其用的网站防护体系

    ​随着互联网新技术的涌现,网站的架构技术和涉及的资源也日益多样且复杂化.这对网站各类资源的防护工作也提出了更高的挑战和更细粒度的需求. 我们经常碰到的用户真实需求包括: 我的 CMS 制作系统,会不会 ...

  2. english note [6.3to6.9]

    6.3 http://www.51voa.com/VOA_Special_English/pakistan-town-struggles-with-rise-in-hiv-infections-821 ...

  3. CF932G-Palindrome Partition【PAM】

    正题 题目链接:https://www.luogu.com.cn/problem/CF932G 题目大意 给出一个长度为\(n\)的字符串,将其分为\(k\)段(\(k\)为任意偶数),记为\(p\) ...

  4. VirtualBox VM 空间瘦身记(vmdk)

    本文地址:https://www.ebpf.top/post/shrink_vbox_vmdk_size 在使用 VirtualBox( VMDK 模式)管理虚拟机的时候,我们经常会遇到一些编译安装场 ...

  5. C++ 可变数组实现

    话不多说,直接上代码,看注释 template<class T> // 支持传入泛型,但string这种可变长度的类型还不支持 class Array { int mSize = 0, m ...

  6. Unity——FSM有限状态机

    FSM有限状态机 一.设计思路 1.共同的状态父类,提供可重写的进入,保持,退出该状态的生命周期方法: 2.状态机,管理所有状态(增删查改),状态机运行方法(Run): 3.在角色控制器中,实例化状态 ...

  7. netty 处理客户端连接

    Netty如何处理连接事件 上文讲了Netty如何绑定端口,现在我们来阅读下netty如何处理connect事件.上文我们说了NioEventLoop启动后不断去调用select的事件,当客户端连接时 ...

  8. 从零入门 Serverless | 教你 7 步快速构建 GitLab 持续集成环境

    作者 | 存诚 阿里云弹性计算团队 本文整理自<Serverless 技术公开课>,"Serverless"公众号后台回复"入门",即可获取系列文章 ...

  9. 2020 年国内 Serverless 用户规模:阿里云占比第一,达 66%

    在中国信息通信研究院重磅发布的国内首个<云原生用户调查报告>中,阿里云 Serverless 产品凭借在双十一的技术锤炼和丰富的应用实践,在国内 Serverless 用户规模的占比达到 ...

  10. Spatial Analyst Tools(Spatial Analyst 工具)

    Spatial Analyst Tools 1.区域分析 # Process: 以表格显示分区几何统计 arcpy.gp.ZonalGeometryAsTable_sa("", & ...