build.groovy 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. pipeline {
  2. agent any
  3. environment {
  4. def appName = "jk-temporary-workers"
  5. def branch = "master"
  6. def host = '121.37.187.149'
  7. }
  8. tools {
  9. // Install the Maven version configured as "M3" and add it to the path.
  10. maven "M3"
  11. jdk "jdk8"
  12. }
  13. stages {
  14. stage('checkout') {
  15. steps {
  16. dir("${env.WORKSPACE}/code"){
  17. git branch: branch,credentialsId: 'cd13504d-d7eb-433f-be4b-4cbeedf0372d', url: 'http://47.92.161.104:10080/shuzhan/jp-employment-server.git'
  18. }
  19. }
  20. }
  21. stage('package') {
  22. steps {
  23. dir("${env.WORKSPACE}/code"){
  24. sh 'mvn -s "/usr/local/maven/apache-maven-3.3.9/conf/jenkins.xml" clean package -Dmaven.test.skip=true -P test'
  25. }
  26. }
  27. }
  28. stage('deploy') {
  29. steps {
  30. script {
  31. dir("${env.WORKSPACE}/code/web/target") {
  32. withCredentials([usernamePassword(credentialsId: host,
  33. passwordVariable: 'pwd', usernameVariable: 'userName')]) {
  34. def sshServer = [:]
  35. sshServer.name = 'huawei server'
  36. sshServer.host = host
  37. sshServer.user = userName
  38. sshServer.password = pwd
  39. sshServer.allowAnyHosts= true
  40. sshCommand remote: sshServer, command: "docker stop ${appName}"
  41. def targetFolder = "/opt/mydocker/tomcat8/jp-employment/webapps"
  42. if(fullUpdate=='true'){
  43. sh "mv web-1.0.0.war web.zip"
  44. sshPut remote: sshServer, from: 'web.zip', into: targetFolder
  45. sshCommand remote: sshServer, command: "rm -rf ${targetFolder}/${appName}-server"
  46. sshCommand remote: sshServer, command: "unzip ${targetFolder}/web.zip -d ${targetFolder}/${appName}-server"
  47. }
  48. else{
  49. //更新 classes
  50. dir("${env.WORKSPACE}/code/web/target/web-1.0.0/WEB-INF/classes"){
  51. sh 'tar -czvf com.tar.gz com'
  52. sshPut remote: sshServer, from: 'com.tar.gz', into: "${targetFolder}/${appName}-server/WEB-INF/classes"
  53. sshCommand remote: sshServer, command: "rm -rf ${targetFolder}/${appName}-server/WEB-INF/classes/com"
  54. sshCommand remote: sshServer, command: "tar -zxvf ${targetFolder}/${appName}-server/WEB-INF/classes/com.tar.gz -C ${targetFolder}/${appName}-server/WEB-INF/classes"
  55. }
  56. //更新 lib
  57. dir("${env.WORKSPACE}/code/web/target/web-1.0.0/WEB-INF/lib"){
  58. sshPut remote: sshServer, from: "common-1.0.0.jar", into: "${targetFolder}/${appName}-server/WEB-INF/lib"
  59. }
  60. }
  61. sshCommand remote: sshServer, command: "docker start ${appName}"
  62. }
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }