声明式流水线示例:
def remote
pipeline {
agent any
stages {
stage('RemoteServer ') {
steps {
script {
remote = [:]
remote.name = 'TMS-test'
remote.host = '192.168.4.1'
remote.user = 'root'
remote.allowAnyHosts = true
}
}
}
stage('Build') {
steps {
git branch: 'develop', credentialsId: 'jenkins发布用户', url: 'http://gitlab.jinkosolar.com/supply-chain/jinkotms-web.git'
withMaven(globalMavenSettingsConfig: '6785dafa-97ee-4c80-', jdk: 'jdk8', maven: 'maven354', mavenSettingsConfig: '-8273-cdf43d7ca43b') {
sh 'mvn clean package '
}
}
tools {
git 'Default'
}
}
stage('SSH Put Jar ') {
steps {
withCredentials([sshUserPrivateKey(credentialsId: 'sshPrivateKeyUser', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) {
script {
remote.identityFile = identity
sshPut remote: remote, from: 'target/jinkotms.jar', into: '/tmp'
}
}
}
}
stage('SSH Restart ') {
steps {
withEnv(['JENKINS_NODE_COOKIE=dontKillMe']) {
withCredentials([sshUserPrivateKey(credentialsId: 'sshPrivateKeyUser', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) {
script {
remote.identityFile = identity
sshCommand remote: remote, command: 'cd /data/app/web/test && pwd && ./jenkins_deploy.sh '
}
}
}
}
}
}
}
标签:pipeline,remote,declarative,steps,credentialsId,Jenkins,identity,stage
From: https://www.cnblogs.com/xysgo/p/16867649.html