Jenkins中使用execute shell script on remote host using ssh

Jenkins中使用execute shell script on remote host using ssh

  • 一. 安装SSH Plugin插件
  • 二. 添加Credentials
  • 三. 远程主机SSH配置
  • 四. 免密登录
  • 五. 在构建项目中ssh远程主机时使用这个远程主机

一. 安装SSH Plugin插件

Jenkins中使用execute shell script on remote host using ssh_第1张图片

二. 添加Credentials

Jenkins中使用execute shell script on remote host using ssh_第2张图片
Jenkins中使用execute shell script on remote host using ssh_第3张图片

Jenkins中使用execute shell script on remote host using ssh_第4张图片

Jenkins中使用execute shell script on remote host using ssh_第5张图片
Jenkins中使用execute shell script on remote host using ssh_第6张图片

三. 远程主机SSH配置

Jenkins中使用execute shell script on remote host using ssh_第7张图片
Jenkins中使用execute shell script on remote host using ssh_第8张图片
Jenkins中使用execute shell script on remote host using ssh_第9张图片

四. 免密登录

jenkins免密登录其他服务器

  1. 在jenkins后台生成公钥、私钥对
[root@jenkins3 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:4bwSPBMDqt1mIGJyOYpXhERIWE804ZDsdDQDDd3BR7s root@jenkins3
The key's randomart image is:
+---[RSA 2048]----+
|oBBX@+.o.        |
|o =O+=o ..       |
|++*.+ o.o        |
|=*.= . = o       |
|+ o + = E        |
| . o   + .       |
|      . .        |
|       .         |
|                 |
+----[SHA256]-----+
[root@jenkins3 ~]# 


  1. 添加凭据-告诉jenkins自己的私钥是什么,jenkins将用这个私钥和对方服务器进行免秘钥认证

Jenkins中使用execute shell script on remote host using ssh_第10张图片

Jenkins中使用execute shell script on remote host using ssh_第11张图片
Jenkins中使用execute shell script on remote host using ssh_第12张图片Jenkins中使用execute shell script on remote host using ssh_第13张图片
3. 将jenkins的公钥复制到对方服务器的authorized_keys

[root@jenkins3 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.30.9's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.30.9'"
and check to make sure that only the key(s) you wanted were added.
  1. 在jenkins上配置登录192.168.30.9这台服务器时使用免密登录

Jenkins中使用execute shell script on remote host using ssh_第14张图片

Jenkins中使用execute shell script on remote host using ssh_第15张图片

  1. 在jenkins后台将自己的私钥复制到jenkins目录
[root@jenkins3 ~]# cp /root/.ssh/id_rsa /var/lib/jenkins/

五. 在构建项目中ssh远程主机时使用这个远程主机

Jenkins中使用execute shell script on remote host using ssh_第16张图片

你可能感兴趣的:(node.js,html5)