build.groovy 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. pipeline {
  2. agent any
  3. stages {
  4. stage('checkout') {
  5. steps {
  6. dir("${env.WORKSPACE}/code"){
  7. git branch: branch,credentialsId: 'cd13504d-d7eb-433f-be4b-4cbeedf0372d', url: 'http://47.92.161.104:10080/shuzhan/jp-employment-portal.git'
  8. }
  9. }
  10. }
  11. stage('package') {
  12. steps {
  13. nodejs('nodejs12') {
  14. //sh 'npm install cnpm -g --registry=https://registry.npm.taobao.org'
  15. //sh 'cnpm -v'
  16. dir("${env.WORKSPACE}/code"){
  17. sh "cnpm install"
  18. sh "npm run build"
  19. }
  20. }
  21. }
  22. }
  23. stage('deploy') {
  24. steps {
  25. script {
  26. dir("${env.WORKSPACE}/code/dist"){
  27. def appName = "jp-employment-portal"
  28. def host = "121.37.187.149"
  29. sh "tar -czvf ${appName}.tar.gz ${appName}"
  30. withCredentials([usernamePassword(credentialsId: host,
  31. passwordVariable: 'pwd', usernameVariable: 'userName')]) {
  32. def sshServer = [:]
  33. sshServer.name = 'huawei server'
  34. sshServer.host = host
  35. sshServer.user = userName
  36. sshServer.password = pwd
  37. sshServer.allowAnyHosts= true
  38. def folder = "/opt/websites";
  39. sshPut remote: sshServer, from: appName + '.tar.gz', into: folder
  40. sshCommand remote: sshServer, command: "rm -rf ${folder}/${appName}"
  41. sshCommand remote: sshServer, command: "tar -zxvf ${folder}/${appName}.tar.gz -C ${folder}"
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }
  48. }