如何在詹金斯的多分支管道中通过ssh发布

问题描述:

我有根目录下带有Jenkinsfile的Maven springboot项目.我已经在jenkins文件中编写了阶段来构建jar文件,并且工作正常.下一阶段是``部署'',我必须将jar文件移动到Linux服务器并在其中运行它.有人可以在jenkinsfile阶段帮助我如何将jar文件从Jenkins服务器移动到另一台服务器并在该服务器上运行.

I have maven springboot project with Jenkinsfile at root. I have written stages in jenkins file to build jar file and it's working fine.Next stage is 'deployment' where i have to move jar file to Linux server and run it there. Could anyone please help me with stage in jenkinsfile how to move jar file from Jenkins server to another server and run it there.

1.您可以使用SSH上发布插件并获取管道语法的语法

1.you can use the Publish over SSH plugin and get the syntax for Pipeline syntax

sshPublisher(publishers: [sshPublisherDesc(configName: 'SERVER_to_be_deployed', transfers: [sshTransfer(excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '**/target/*.war')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])

2.您只需使用scp命令即可在计算机之间传输文件

2.you can just use a scp command to transfer files across machines

scp [options] username1@source_host:directory1/filename1 username2@destination_host:directory2/filename2

3.curl做同样的事情

3.curl to do the same

curl -u username:password -T /path/to/file.txt sftp://host.com:22/file.txt

您想使用哪一种:)