.drone.yml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # drone 自动构建
  2. name: test-project autodeploy
  3. kind: pipeline
  4. type: docker
  5. clone:
  6. # 不需要拉取 commit 历史,加快速度
  7. depth: 1
  8. # 需要 clone
  9. disable: false
  10. # drone 构建步骤
  11. steps:
  12. - name: Compile & Package
  13. pull: if-not-exists
  14. image: cnlym/maven:3-jdk-21-alpine-aliyun
  15. commands:
  16. # 开始打包maven工程 跳过测试步骤
  17. - mvn clean package -Dmaven.test.skip=true -T 1C
  18. - cp target/executable.jar ./executable.jar
  19. - name: Upload Jar
  20. pull: if-not-exists
  21. image: appleboy/drone-scp
  22. settings:
  23. host:
  24. from_secret: ssh_host
  25. username:
  26. from_secret: ssh_user
  27. password:
  28. from_secret: ssh_pwd
  29. port:
  30. from_secret: ssh_port
  31. target: /opt/bin/java
  32. #cicd/${DRONE_REPO_NAME}
  33. source: ./executable.jar
  34. when:
  35. branch:
  36. - master
  37. - name: SSH & Start
  38. pull: if-not-exists
  39. image: appleboy/drone-ssh
  40. settings:
  41. host:
  42. from_secret: ssh_host
  43. username:
  44. from_secret: ssh_user
  45. password:
  46. from_secret: ssh_pwd
  47. port:
  48. from_secret: ssh_port
  49. # TODO 【优化】cicd部署脚本未返回,而是10min超时,这个现象其他人也有遇到 https://github.com/appleboy/drone-ssh/issues/125
  50. command_timeout: 9m
  51. script:
  52. # 运行部署脚本
  53. #- cd /opt/bin/java/cicd
  54. # 停掉进程
  55. - /opt/bin/java/tryStop.sh
  56. # 搬运之前的日志
  57. - mkdir -p /opt/bin/java/historyLogs
  58. - mv /opt/bin/java/logs /opt/bin/java/historyLogs/before_build_${DRONE_BUILD_NUMBER}
  59. - mkdir -p /opt/bin/java/logs
  60. - echo '${DRONE_BUILD_NUMBER}' > /opt/bin/java/logs/drone_ci_build.no
  61. - date > /opt/bin/java/logs/drone_ci_build.time
  62. - /opt/bin/java/run.sh
  63. # 部署命令一定要放到drone的最后一条命令,这样在脚本中抛出异常退出后,drone可以捕捉到异常退出,将该次构建标记为构建失败
  64. - /opt/bin/java/syncDetectAppHasStart.sh PomUpdateApplication
  65. when:
  66. branch:
  67. - master
  68. # 每5s检测health端口启动成功,10min超时
  69. # - name: SSH & Start
  70. # pull: if-not-exists
  71. # image: appleboy/drone-ssh
  72. - name: Build Notification. --- with DingTalk
  73. image: guoxudongdocker/drone-dingtalk
  74. settings:
  75. token:
  76. from_secret: ding_token
  77. type: markdown
  78. # drone执行触发分支
  79. trigger:
  80. branch:
  81. - master
  82. event:
  83. - push