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. Yaml书写方法详解

    一.关于yaml语法详解 yaml通常以空格做锁进,一般是2个或者4个,如果写更多,只要格式对其 就不会报错 二.yaml基本语法规则 大小写敏感 使用锁进表示层级关系 缩紧时候不允许用tab键,只能 ...

  2. 理解classpath

    一.什么是classpath classpath,翻译过来就是类路径的意思,它是包含class文件的路径集合,用于指示虚拟机jvm在这些路径下搜索class文件. 类路径可以同时定义多个,多个类路径之 ...

  3. kubeadm 如何将节点加入集群

    kubeadm join 使用 token 过期之后(24小时过期),如何加入集群 一.重启生成新token # 创建新token kubeadm token create # 查看是否存在有效的 t ...

  4. Monte-carlo-simulation

    https://towardsdatascience.com/how-to-use-monte-carlo-simulation-to-help-decision-making-a0a164bc861 ...

  5. kendoUI 多选下拉列表 kendoMultiSelect

    问题1:被重复渲染 点击新增按钮----弹出模态框 多选下拉列表在多选框中只是初始化过一次.但是每次点击新增后  发现 多选下拉列表 被重复渲染了 解决方案 在 新增时  先将其父元素div中  的s ...

  6. nodejs 安装 报错解决方案

    win10安装nodejs之后,查看版本号在终端输入node -v成功输出版本号,输入npm -v 之后报错...... 反复安装卸载之后,有点奔溃,最后的解决方案是:手动删除"C:\Use ...

  7. 深入剖析 Spring WebFlux

    一.WebFlux 简介 WebFlux 是 Spring Framework5.0 中引入的一种新的反应式Web框架.通过Reactor项目实现Reactive Streams规范,完全异步和非阻塞 ...

  8. ECMA 2022 (es13) 新特性

    本文主要整理了截至到 2021年10月12日 为止的且处于 Stage 3->Stage 4 阶段的ECMA提案. 主要包括: Class Fields RegExp Match Indices ...

  9. The type name or alias SqlServer could not be resolved.Please check your configuration

    The type name or alias SqlServer could not be resolved.Please check your configuration file.... 检查一下 ...

  10. CQOI2021 退役记

    Day -1 晚上去了酒店然后就睡觉了. Day 1 进考场之前互相奶. 进了考场之后看题,发现T1很水(伏笔1,然后直接开始写 \(\Theta(n\log^2n)\)(二分+动态开点线段树),调了 ...