import java.text.SimpleDateFormatdef getRemoteServer(ip){ def remote = [:] remote.name = 'root' remote.host = ip remote.user = 'root' remote.password = 'xxxxxx' remote.allowAnyHosts = true // withCredentials([usernamePassword(credentialsId: 'wukang', passwordVariable: 'password', usernameVariable: 'userName')]) { // remote.user = "${userName}" // remote.password = "${password}" // } return remote}def time = '222222'// parameters {// booleanParam(name: 'isPublishVersion', defaultValue: false, description: '默认不发布')// choice(choices: ['origin/release-bugfix', 'origin/release', 'origin/master'], description: '构建分支选择,默认origin/release-bugfix' , name: 'GIT_LOCAL_BRANCH')// }pipeline { agent any parameters { gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'BRANCH', type: 'PT_BRANCH' } stages {// stage('连接跳板机') {// steps {// script{// remote = getRemoteServer("192.168.0.9")// sshCommand remote: remote, command: "ls -lrt"// sshCommand remote: remote, command: "for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done"// }// }// } stage('拉取代码') { steps { git branch: "${params.BRANCH}", credentialsId: 'c2232f1a-c44c-4ac8-956d-92b40e4343d3', url: 'http://192.168.0.212/npay/code/mlang.git' } } stage('编译构建') { steps { sh 'mvn clean package' } } stage('上传ftp') { steps { script{ def dateFormat = new SimpleDateFormat("yyyyMMddHHmm") def date = new Date() time = dateFormat.format(date) } sh """lftp <<ENDopen 47.243.85.49 -p 21user deploy fccFbBGfvtjpYFGm cd data_centermkdir ${time}cd ${time}mkdir codemkdir confcd codemput target/*.jarlsENDecho "上传在ftp目录:/data_center/${time}/code/" """ } } stage('代码部署') { steps { script{ remote = getRemoteServer("192.168.0.9") sshCommand remote: remote, command: "cd /data/files;wget -nH -r ftp://deploy:xxxxx@47.243.85.49/data_center/${time}" } echo '代码部署' echo "/data_center/${time}/code/" // sh 'ansible all -m ping' } } stage('配置分发') { steps { echo '配置分发' } } stage('重启服务') { steps { echo '重启服务' } } }}