Jenkins sends files to remote servers: Publish Over SSH plugin

Jenkins sends files to remote servers: Publish Over SSH plugin

Explanation: The following tutorial may be a "stupid" tutorial, because I haven't done it before, and I just learned it now, and I will improve it later!

1. Publish Over SSH plugin

1 Overview

The Publish Over SSH plugin is a plugin for Jenkins that provides the ability to transfer files and execute commands with remote servers via the SSH protocol .

2. Main functions and features

  1. SSH connection management : You can configure multiple SSH server connections in the global configuration of Jenkins , and specify information such as host name, user name, password/key, port number, etc. for each connection. This way, different SSH connections can be easily managed and reused.
  2. File transfer : Through the Publish Over SSH plug-in, the specified file or directory can be sent from the Jenkins host to the remote server. Multiple files can be specified using wildcards , or a directory path on the target server can be set. There is an option to keep or delete local files after the transfer is complete.
  3. Remote Command Execution : In addition to file transfers, this plugin allows custom shell commands or scripts to be executed on remote servers . You can specify the command to be executed in the SSH operation, and support the use of environment variables in the command.
  4. Build triggers : You can use SSH operations as part of the Jenkins build process, or use the plugin as a standalone build trigger . Plugins can be configured to perform remote actions before a build starts, after a build ends, or when a build fails.
  5. Advanced Configuration Options : The plugin provides some advanced configuration options such as timeout, proxy settings, command execution before and after transfer , etc. These options can be adjusted as needed to meet specific needs.

3. Plug-in home page

https://plugins.jenkins.io/publish-over-ssh/

4. Install the Publish Over SSH plugin

image-20230623113602795

5. Configure the remote host

image-20230623114004756

Second, send the file to the remote host

1. Create a new project

image-20230623114400606

2. Add the send file step in the build step

image-20230623114530996

3. File sending configuration

image-20230623115220496

4. Save and build immediately

image-20230623115440828

5. The result of the first build

image-20230623120117670

6. File upload failed

The file upload failed because the file needs to be under the workspace of the current project (as far as the current configuration is concerned), and the workspace was not generated before it was built.

image-20230623120415369

7. Put the target file into the workspace

image-20230623120539422

8. The second build

image-20230623120750794

9. View the remote server directory

image-20230623120832698

3. Send multiple files and send directories

1. Separate multiple files with commas

Make sure there are these files in the workspace!

image-20230623121114612

2. File matching

# 根目录下以“2.txt”结尾的文件
*2.txt
# 根目录下的所有子目录中以“2.txt”结尾的文件
**/*2.txt

image-20230623121730437

3. Directory

files/**

image-20230623122119547

Guess you like

Origin blog.csdn.net/qq_29689343/article/details/131349578