概述
JENKINS通过跳板机上传文件
pipeline {
agent any
stages {
stage('Build') {
steps {
// Get some code from a GitHub repository
git 'https://gitee.com/yeyeyeyeto/SpringBootTest.git'
bat 'mvn clean package -DskipTests'
}
}
stage('SSH') {
steps {
script {
def remote = [:]
remote.name = 'test'
remote.host = '124.223.222.123'
remote.port = 2222
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: '124.223.222.123', passwordVariable: 'password', usernameVariable: 'username')]) {
remote.user = "${username}"
remote.password = "${password}"
}
sshCommand remote: remote, command: " sshpass -p '目标机密码' ssh -p 22 root@10.0.4.9 'echo 'wudasdasdasdi' > test.txt' "
sshPut remote: remote, from: './target/springboottest1-0.0.1-SNAPSHOT.jar', into: '/opt/project/test/'
sshCommand remote: remote, command: " sshpass -p '目标机密码' scp -o 'StrictHostKeyChecking no' -P 22 '/opt/project/test/springboottest1-0.0.1-SNAPSHOT.jar' root@10.0.4.9:/opt/project/test/springboottest1-0.0.1-SNAPSHOT.jar"
}
}
}
}
}
二、文件夹目录复制
pipeline {
agent any
stages {
stage('Build') {
steps {
// Get some code from a GitHub repository
git 'https://gitee.com/yeyeyeyeto/SpringBootTest.git'
bat 'mvn clean package -DskipTests'
}
}
stage('SSH') {
steps {
script {
def remote = [:]
remote.name = 'test'
remote.host = '124.223.222.123'
remote.port = 2222
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: '124.223.222.123', passwordVariable: 'password', usernameVariable: 'username')]) {
remote.user = "${username}"
remote.password = "${password}"
}
sshCommand remote: remote, command: " sshpass -p '目标机密码' ssh -p 22 root@10.0.4.9 'echo 'wudasdasdasdi' > test.txt' "
sshPut remote: remote, from: './target', into: '/opt/project/test/'
sshCommand remote: remote, command: " sshpass -p '目标机密码' scp -o 'StrictHostKeyChecking no' -P 22 -r '/opt/project/test/target' root@10.0.4.9:/opt/project/test"
}
}
}
}
}
三、使用加密信息,防止密码泄露
pipeline {
agent any
stages {
stage('Build') {
steps {
// Get some code from a GitHub repository
git 'https://gitee.com/yeyeyeyeto/SpringBootTest.git'
bat 'mvn clean package -DskipTests'
}
}
stage('SSH') {
steps {
script {
def remote = [:]
remote.name = 'test'
remote.host = '124.223.222.123'
remote.port = 2222
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: '124.223.222.123', passwordVariable: 'password', usernameVariable: 'username')]) {
remote.user = "${username}"
remote.password = "${password}"
}
sshCommand remote: remote, command: " sshpass -p 'A!199662' ssh -p 22 root@10.0.4.9 'echo 'wudasdasdasdi' > test.txt' "
sshPut remote: remote, from: './target', into: '/opt/project/test/'
withCredentials([usernamePassword(credentialsId: '1.117.77.230', passwordVariable: 'password', usernameVariable: 'username')]) {
sshCommand remote: remote, command: " sshpass -p '${password}' scp -o 'StrictHostKeyChecking no' -P 22 -r '/opt/project/test/target' root@10.0.4.9:/opt/project/test"
}
}
}
}
}
}
最后
以上就是儒雅手链为你收集整理的jenkins通过跳板机上传文件的全部内容,希望文章能够帮你解决jenkins通过跳板机上传文件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复