Jenkinsfile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. pipeline {
  2. agent any
  3. environment {
  4. BUILD_USER = ""
  5. REMOTE_PATH = "/mdata/cooleshow-test/jenkins"
  6. BUILD_FILE = "libs.tar.gz"
  7. ROBOT_ID = "a346e21b-706e-4881-8e3b-6c48d16d0c3b"
  8. SSH_AUTH = "WH-COOLESHOW-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. // 构建项目
  24. sh 'mvn clean package'
  25. // 打包Jar包
  26. sh " \
  27. rm -rf ./libs && mkdir libs \
  28. && cp service.md \
  29. cooleshow-user/user-admin/target/user-admin.jar \
  30. audio-analysis/target/audio-analysis.jar \
  31. cooleshow-auth/auth-server/target/auth-server.jar \
  32. cooleshow-bbs/target/cooleshow-bbs.jar \
  33. cooleshow-user/user-classroom/target/user-classroom.jar \
  34. cooleshow-cms/target/cooleshow-cms.jar \
  35. cooleshow-gateway/gateway-web/target/gateway-web.jar \
  36. cooleshow-mall/mall-admin/target/mall-admin.jar \
  37. cooleshow-mall/mall-portal/target/mall-portal.jar \
  38. cooleshow-user/user-student/target/user-student.jar \
  39. cooleshow-task/target/cooleshow-task.jar \
  40. cooleshow-user/user-teacher/target/user-teacher.jar \
  41. cooleshow-user/user-website/target/user-website.jar \
  42. cooleshow-websocket/target/cooleshow-websocket.jar \
  43. libs/ \
  44. && tar -zcf ${BUILD_FILE} libs/ \
  45. "
  46. }
  47. }
  48. stage('deploy job') {
  49. steps {
  50. sshPublisher(publishers: [sshPublisherDesc(configName: "${SSH_AUTH}", transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "cd ${REMOTE_PATH} && ./jenkins-server.sh > jenkins.log", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: "${REMOTE_PATH}", remoteDirectorySDF: false, removePrefix: '', sourceFiles: '**/*.tar.gz')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
  51. }
  52. }
  53. stage('clean job') {
  54. steps {
  55. sh "rm -rf ./libs && rm -f ${BUILD_FILE}"
  56. }
  57. }
  58. }
  59. post {
  60. success {
  61. dingtalk (
  62. robot: "a346e21b-706e-4881-8e3b-6c48d16d0c3b",
  63. type:'ACTION_CARD',
  64. atAll: false,
  65. title: "构建成功:${env.JOB_NAME}",
  66. //messageUrl: 'xxxx',
  67. text: [
  68. "### [${env.JOB_NAME}](${env.JOB_URL}) ",
  69. '---',
  70. "- 任务:[${currentBuild.displayName}](${env.BUILD_URL})",
  71. '- 状态:<font color=#00CD00 >成功</font>',
  72. "- 持续时间:${currentBuild.durationString}".split("and counting")[0],
  73. "- 执行人:${BUILD_USER}",
  74. ]
  75. )
  76. }
  77. failure{
  78. dingtalk (
  79. robot: "a346e21b-706e-4881-8e3b-6c48d16d0c3b",
  80. type:'ACTION_CARD',
  81. atAll: false,
  82. title: "构建失败:${env.JOB_NAME}",
  83. //messageUrl: 'xxxx',
  84. text: [
  85. "### [${env.JOB_NAME}](${env.JOB_URL}) ",
  86. '---',
  87. "- 任务:[${currentBuild.displayName}](${env.BUILD_URL})",
  88. '- 状态:<font color=#EE0000 >失败</font>',
  89. "- 持续时间:${currentBuild.durationString}".split("and counting")[0],
  90. "- 执行人:${BUILD_USER}",
  91. ]
  92. )
  93. }
  94. }
  95. }