Jenkins-declarative-pipeline

声明式流水线示例:

官方文档

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 '
                            }
                        }
                    }
                }
        }
    }
}
posted @ 2023-02-12 20:29  菜阿  阅读(41)  评论(0编辑  收藏  举报