devops學習-Jenkins Pipeline SSH 的實現


需要安裝SSH 插件

 

參考文檔
https://github.com/jenkinsci/ssh-steps-plugin#pipeline-steps
需要
在jenkins 添加憑據

def remote = [:] remote.name = "node-1" remote.host = "10.000.000.153" remote.allowAnyHosts = true node {  withCredentials([usernamePassword(credentialsId: '83b448c0-20d9-47f5-8f63-c1765df8df5c', passwordVariable: 'password', usernameVariable: 'userName')]) { { remote.user = userName  remote.password = password stage("SSH Steps Rocks!") { writeFile file: 'abc.sh', text: 'ls' sshCommand remote: remote, command: 'for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done' sshPut remote: remote, from: 'abc.sh', into: '.' sshGet remote: remote, from: 'abc.sh', into: 'bac.sh', override: true sshScript remote: remote, script: 'abc.sh' sshRemove remote: remote, path: 'abc.sh' } } }
def remote = [:] remote.name = "node-1" remote.host = "10.000.000.153" remote.allowAnyHosts = true node { withCredentials([sshUserPrivateKey(credentialsId: 'sshUser', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) { remote.user = userName remote.identityFile = identity stage("SSH Steps Rocks!") { writeFile file: 'abc.sh', text: 'ls' sshCommand remote: remote, command: 'for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done' sshPut remote: remote, from: 'abc.sh', into: '.' sshGet remote: remote, from: 'abc.sh', into: 'bac.sh', override: true sshScript remote: remote, script: 'abc.sh' sshRemove remote: remote, path: 'abc.sh' } } }

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM