「Jenkins」- Publish Over ...(学习笔记) @20210421

The goal of the Publish Over plugins is to provide a consistent set of features and behaviours when sending build artifacts ... somewhere.

Publish Over plugins

Publish Over CIFS Plugin - send artifacts to a windows share
Publish Over FTP Plugin - send artifacts to an FTP server
Publish Over SSH Plugin - send artifacts to an SSH server (using SFTP) and/or execute commands over SSH

Overview & Configuration

Host configurations are created in the main Jenkins configuration (Manage Jenkins > Configure System). The host configurations define how to initiate connections to the remote server.

The publisher is configured in a job by selecting the checkbox next to Publish Over ... (eg. Publish over FTP) (The publisher is also available as an action during a promotion if you have installed the Promoted Builds Plugin

One or more servers are selected and configured as destinations for transfer sets.

One or more transfer sets are configured to select the files to send, and where to send them.

Host configurations

创建主机配置,用于从作业配置页面中选择。

这是算是一个公共的配置,位于:Jenkins - Manage Jenkins - Configure System - Publish over XXX

要更改主机在作业配置页面下拉列表中显示的顺序,可以拖动“方形”图标,以重新排序列表。

由于主机配置指定了如何连接到远程服务器,因此配置可能非常特定于插件(即SSH密钥,被动模式FTP等)。

首次配置或更改配置时,可以单击“Test Configuration”,以确保在从作业中使用配置时该配置将起作用。如果一切顺利,那么你应该看到“SUCCESS”,否则你会看到一条红色的消息。

Publisher

这是特定与作业的,所以是在作业页面进行设置的,「“某个项目” - Build - Add build step - Send files or execute commands over SSH」,然后选择主机,设置参数即可。

在发布者级别设置了一些选项 - 影响其中所有服务器连接的选项。只有在单击“高级”按钮(位于此插件的配置底部)时,才会显示所有发布者选项。

Server

Server位于Publisher中,这个针对Server进行一些单独的配置,以覆盖Host configurations中的主机配置。

Transfer set

文件发送设置。比如指定远程目录,移除路径前缀,发送目录,排除目录,执行命令等等。

Transfer set位于Server中,一个Server可以添加多个Transfer set,并拥有不同的配置。

这四者之间的关系总结

Host configurations - 全局的主机配置,配置可以使用的主机。

Publisher - 位于作业中。

Server - 位于作业中的Publisher中,指定了用于接收发布的主机。

Transfer set - 位于Server中,用于指定要向主机发送的文件集等等操作。

注意事项

经验之谈,如果你的代码量、文件数比较少,你可以用这种方法,毕竟这些插件并不包含增量同步功能。所以,如果文件的项目比较多,即使改动了几个文件,它们也会把所有的文件进行上传,所以时间会比较长,并且发送了不需要发送的文件,因此花费的时间也比较久。当我第一次使用Publish Over SSH时,时间比较久,看了以下目录,恍然想起来它只是SSH上传,会发送所有的文件,时间当让会很久。

如果是打包的项目,比如war文件,可以使用这种方法。

相关文章

「Jenkins Plugins」- Email Extension
「Jenkins Plugins」- Git
「Jenkins」- GitLab Plugin
「Jenkins Plugins」- Token Macro
「Jenkins」- Webhook (Gitlab、Gitee)

参考文献

Jenkins/Publish Over
Jenkins/Publish Over SSH Plugin
jenkins通过SSH Publishers自动构建发包到远程服务器


posted @ 2021-04-21 22:20  研究林纳斯写的  阅读(94)  评论(0编辑  收藏  举报