How to publish over ssh in multibranch pipeline in jenkins

为君一笑 提交于 2019-12-11 18:24:28

问题


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:


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.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 to do the same

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

Which one would you like to use :)



来源:https://stackoverflow.com/questions/50376212/how-to-publish-over-ssh-in-multibranch-pipeline-in-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!