一、安装插件
Publish Over SSH
SSH Pipeline Steps
二、添加sshkey
将ssh免密登录的私钥新建到
二、准备目录
源:images
目标:/root/images2
流水线脚本
pipeline {
agent any
stages {
stage('Dest') {
steps {
script{
def remote = [:]
remote.name = 'tst'
remote.host = '192.168.31.142'
remote.port = 22
remote.allowAnyHosts = true
sh 'tar czvf demo.tar.gz ./images/*'
withCredentials([sshUserPrivateKey(credentialsId: 'linux-142-ssh', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) {
remote.user = userName
remote.identityFile = identity
sshPut remote:remote,from:'./demo.tar.gz',into:'/root/images2/'
sshCommand remote:remote,command:"cd /root/images2/ && sudo tar xzvf demo.tar.gz"
}
}
}
}
}
}