Jenkins sends files to remote servers: Publish Over SSH plugin
Article directory
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
- 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.
- 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.
- 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.
- 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.
- 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
5. Configure the remote host
Second, send the file to the remote host
1. Create a new project
2. Add the send file step in the build step
3. File sending configuration
4. Save and build immediately
5. The result of the first build
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.
7. Put the target file into the workspace
8. The second build
9. View the remote server directory
3. Send multiple files and send directories
1. Separate multiple files with commas
Make sure there are these files in the workspace!
2. File matching
# 根目录下以“2.txt”结尾的文件
*2.txt
# 根目录下的所有子目录中以“2.txt”结尾的文件
**/*2.txt
3. Directory
files/**