Jenkins Publish over SSH plugin configuration and server mutual trust

Original link: https://www.iyouhun.com/post-234.html

Server mutual trust

A server: the server where Jenkins is located

B server: the server where the project is deployed

A server generates a secret key

 ssh-keygen # 一路回车

The A server installs the local ssh public key file to the account corresponding to the remote host (it can also be copied manually, the recommended command)

 # 执行命令后输入密码完成复制ssh-copy-id [email protected]服务器IP #端口不一致复制方法ssh-copy-id -i /root/.ssh/id_rsa.pub "-p 1008 [email protected]服务器IP" # 使用该命令测试ssh [email protected]服务器IP # 登录后注意此时主机名已经是B 服务器的了查看命令hostname # 修改主机名centos6 vim /etc/sysconfig/network #编辑network文件修改hostname行(重启生效) # 检查修改cat /etc/sysconfig/network # 修改主机名centos7 hostnamectl set-hostname www.iyouhun.com # 使用这个命令会立即生效且重启也生效

The copied file is named authorized_keys under the home/用户名/.ssh/ file

 # 比如新建了一个Jenkins账户cat /home/jenkins/.ssh/authorized_keys # root 账户在cat /root/.ssh/authorized_keys

Publish over SSH plugin configuration

Passphrase : If you entered a password when generating the secret key, enter it here, otherwise leave it blank

Path to Key : The path of the server secret key ( id_rsa ) where Jenkins is located, and choose one of the following Keys

Key : The path content of the server secret key ( id_rsa ) where Jenkins is located, and choose one of the above Path to Key

Disable exec : disable command execution, remove the ability to execute commands from this plugin

SSH Servers

Name : name, identification, customized, only used for identification

Host name : the host name, the host name or IP address of the server, fill in the IP address of the B server here

Username : The user that will be used to connect to the host, such as root

Remote directory : A directory on the remote server that will be used as a valid root directory for this configuration, such as /www/wwwroot

advanced options

Use password authentication, or use a different key You can check use password connection or secret key connection

Passphrase / Password : Secret key password or username password

Path to Key : The path of the server secret key ( id_rsa ) where Jenkins is located, and choose one of the following Keys

Key : The path content of the server secret key ( id_rsa ) where Jenkins is located, and choose one of the above Path to Key

If you use the key link remember here is the private key ( id_rsa ) of Jenkins (A server)

Port : the remote server port, if you change the port, remember to change it here too

More references: https://wiki.jenkins.io/display/JENKINS/Publish+Over#PublishOver-host

Project publish settings

1. Click on the build environment of the Jenkins project

2. Select the following two according to the project situation

3. Select the publisher you just added

4. Transfer Settings

Source files : source files, support all matching, if you want to transfer all files and folders in the folder, you need to add two * symbol pattern documents after the folder path

Remove prefix : Remove prefix, which refers to the prefix of the source file. For example, now we only transfer all files in the html folder, but the html folder itself does not need to appear on the remote server, so it needs to be removed.

Remote directory : The remote server directory, note that this directory is relative to the path set in the ssh servers in the system settings just now, it will not be created

Then my directory this time is /www/wwwroot/www.iyouhun.com

exec command : The command to be executed after the transfer is completed, generally cleaning files, copying files, restarting some services, etc.

This article is reprinted from: https://www.iyouhun.com/post-234.html
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment

Your email address will not be published.