12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- pipeline {
- agent any
- environment {
- def appName = "jk-temporary-workers"
- def branch = "master"
- def host = '121.37.187.149'
- }
- tools {
- // Install the Maven version configured as "M3" and add it to the path.
- maven "M3"
- jdk "jdk8"
- }
- stages {
- stage('checkout') {
- steps {
- dir("${env.WORKSPACE}/code"){
- git branch: branch,credentialsId: 'cd13504d-d7eb-433f-be4b-4cbeedf0372d', url: 'http://47.92.161.104:10080/shuzhan/jp-employment-server.git'
- }
- }
- }
- stage('package') {
- steps {
- dir("${env.WORKSPACE}/code"){
- sh 'mvn -s "/usr/local/maven/apache-maven-3.3.9/conf/jenkins.xml" clean package -Dmaven.test.skip=true -P test'
- }
- }
- }
- stage('deploy') {
- steps {
- script {
- dir("${env.WORKSPACE}/code/web/target") {
- withCredentials([usernamePassword(credentialsId: host,
- passwordVariable: 'pwd', usernameVariable: 'userName')]) {
- def sshServer = [:]
- sshServer.name = 'huawei server'
- sshServer.host = host
- sshServer.user = userName
- sshServer.password = pwd
- sshServer.allowAnyHosts= true
- sshCommand remote: sshServer, command: "docker stop ${appName}"
- def targetFolder = "/opt/mydocker/tomcat8/jp-employment/webapps"
- if(fullUpdate=='true'){
- sh "mv web-1.0.0.war web.zip"
- sshPut remote: sshServer, from: 'web.zip', into: targetFolder
- sshCommand remote: sshServer, command: "rm -rf ${targetFolder}/${appName}-server"
- sshCommand remote: sshServer, command: "unzip ${targetFolder}/web.zip -d ${targetFolder}/${appName}-server"
- }
- else{
- //更新 classes
- dir("${env.WORKSPACE}/code/web/target/web-1.0.0/WEB-INF/classes"){
- sh 'tar -czvf com.tar.gz com'
- sshPut remote: sshServer, from: 'com.tar.gz', into: "${targetFolder}/${appName}-server/WEB-INF/classes"
- sshCommand remote: sshServer, command: "rm -rf ${targetFolder}/${appName}-server/WEB-INF/classes/com"
- sshCommand remote: sshServer, command: "tar -zxvf ${targetFolder}/${appName}-server/WEB-INF/classes/com.tar.gz -C ${targetFolder}/${appName}-server/WEB-INF/classes"
- }
- //更新 lib
- dir("${env.WORKSPACE}/code/web/target/web-1.0.0/WEB-INF/lib"){
- sshPut remote: sshServer, from: "common-1.0.0.jar", into: "${targetFolder}/${appName}-server/WEB-INF/lib"
- }
- }
- sshCommand remote: sshServer, command: "docker start ${appName}"
- }
- }
- }
- }
- }
- }
- }
|