build.groovy 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. pipeline {
  2. agent any
  3. environment {
  4. def appName = "jp-employment"
  5. def branch = "master"
  6. }
  7. tools {
  8. // Install the Maven version configured as "M3" and add it to the path.
  9. maven "M3"
  10. jdk "jdk8"
  11. }
  12. stages {
  13. stage('checkout') {
  14. steps {
  15. dir("${env.WORKSPACE}/code"){
  16. git branch: branch,credentialsId: 'cd13504d-d7eb-433f-be4b-4cbeedf0372d', url: 'http://47.92.161.104:10080/shuzhan/jp-employment-server.git'
  17. }
  18. }
  19. }
  20. stage('package') {
  21. steps {
  22. dir("${env.WORKSPACE}/code"){
  23. sh 'mvn clean package -Dmaven.test.skip=true -P test -s /usr/maven/apache-maven-3.3.9/conf/settings.xml'
  24. }
  25. }
  26. }
  27. stage('deploy') {
  28. steps {
  29. script {
  30. dir("${env.WORKSPACE}/code/web/target") {
  31. def host = '121.37.187.149'
  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}-server"
  41. if(fullUpdate){
  42. def targetFolder = '/opt/mydocker/tomcat8/jp-employment/webapps/'
  43. sshPut remote: sshServer, from: 'web-1.0.0.war', into: targetFolder
  44. sshCommand remote: sshServer, command: 'rm -rf ${targetFolder}/'
  45. sshCommand remote: sshServer, command: 'unzip ${targetFolder}/web-1.0.0.war -D jp-employment-server'
  46. }
  47. def appName = 'demo1'
  48. sshCommand remote: sshServer, command: "docker stop $appName"
  49. sshCommand remote: sshServer, command: "docker rm $appName"
  50. sshCommand remote: sshServer, command: "docker run --name $appName -p 9091:80 -d $imageName"
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }