Jenkinsfile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. pipeline {
  2. agent any
  3. environment {
  4. BUILD_USER = ""
  5. REMOTE_PATH = "/mdata/www/mdaya-shop"
  6. BUILD_FILE = "dist.tar.gz"
  7. ROBOT_ID = "a346e21b-706e-4881-8e3b-6c48d16d0c3b"
  8. SSH_AUTH = "WH-MEC-TEST"
  9. }
  10. stages {
  11. stage('build param') {
  12. steps {
  13. wrap([$class: 'BuildUser']) {
  14. script {
  15. BUILD_USER = "${env.BUILD_USER}"
  16. }
  17. }
  18. echo '${BUILD_USER}'
  19. }
  20. }
  21. stage('build job') {
  22. steps {
  23. sh 'node -v'
  24. sh 'npm install && npm run build'
  25. sh "tar -zcf ${BUILD_FILE} dist/"
  26. }
  27. }
  28. stage('deploy job') {
  29. steps {
  30. sshPublisher(publishers: [sshPublisherDesc(configName: "${SSH_AUTH}", transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "cd ${REMOTE_PATH} && rm -rf dist/ && tar -zxf *.tar.gz && rm *.tar.gz", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: "${REMOTE_PATH}", remoteDirectorySDF: false, removePrefix: '', sourceFiles: '**/*.tar.gz')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
  31. }
  32. }
  33. stage('clean job') {
  34. steps {
  35. sh "rm ${BUILD_FILE}"
  36. }
  37. }
  38. }
  39. post {
  40. success {
  41. dingtalk (
  42. robot: "${ROBOT_ID}",
  43. type:'ACTION_CARD',
  44. atAll: false,
  45. title: "构建成功:${env.JOB_NAME}",
  46. //messageUrl: 'xxxx',
  47. text: [
  48. "### [${env.JOB_NAME}](${env.JOB_URL}) ",
  49. '---',
  50. "- 任务:[${currentBuild.displayName}](${env.BUILD_URL})",
  51. '- 状态:<font color=#00CD00 >成功</font>',
  52. "- 持续时间:${currentBuild.durationString}".split("and counting")[0],
  53. "- 执行人:${BUILD_USER}",
  54. ]
  55. )
  56. }
  57. failure{
  58. dingtalk (
  59. robot: "${ROBOT_ID}",
  60. type:'ACTION_CARD',
  61. atAll: false,
  62. title: "构建失败:${env.JOB_NAME}",
  63. //messageUrl: 'xxxx',
  64. text: [
  65. "### [${env.JOB_NAME}](${env.JOB_URL}) ",
  66. '---',
  67. "- 任务:[${currentBuild.displayName}](${env.BUILD_URL})",
  68. '- 状态:<font color=#EE0000 >失败</font>',
  69. "- 持续时间:${currentBuild.durationString}".split("and counting")[0],
  70. "- 执行人:${BUILD_USER}",
  71. ]
  72. )
  73. }
  74. }
  75. }