.drone.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. kind: pipeline
  2. name: default
  3. # 内置变量,通知用
  4. # https://docs.drone.io/pipeline/environment/reference/
  5. # dingtalk 官方文档: https://open.dingtalk.com/document/orgapp/enterprise-internal-robots-send-markdown-messages
  6. # type: ssh # 定义流水线类型,还有kubernetes、exec、docker等类型
  7. #server:
  8. # host: 127.0.0.1
  9. # user: root
  10. # password:
  11. # from_secret: passwdlocal # 可以在你的drone web界面设置里进行设置,这儿直接引用
  12. # 用的是树莓派所以架构要用arm64 正常 platform 这项就不用写了
  13. #platform:
  14. # os: linux
  15. # arch: amd64
  16. # 指定运行 runner,不需要
  17. # node:
  18. # name: pi-runner
  19. clone:
  20. depth: 1 # 定义git克隆的深度,这里只需要完整的克隆项目就行,之前的提交并不需要去克隆
  21. disable: false
  22. # CICD 常用插件说明 https://notes.lzwang.ltd/DevOps/CICD/drone_plugin_review/
  23. # 远程与运维¶
  24. # git clone 仓库(默认启用): Drone Plugins - Git
  25. # 执行 git push 到指定仓库: Drone Plugins - Git Push
  26. # 执行 Ansible Playbook: Drone Plugins - Ansible
  27. # SSH登录到远程主机: Drone Plugins - SSH
  28. # 制品上传下载与签名¶
  29. # 对制品进行GPG签名: Drone Plugins - GPG Sign
  30. # 上传制品到WebDAV服务器上: Drone Plugins - WebDAV
  31. # 上传制品到FTP服务器上: Drone Plugins - FTP(S)
  32. # 上传制品到SCP服务器上: Drone Plugins - SCP
  33. # 下载文件到本地用于此次构建: Drone Plugins - Download
  34. # 发布¶
  35. # 推送文件到Codecov进行覆盖率检查: Drone Plugins - Codecov
  36. # 发布镜像到Docker Registry: (1) Drone Plugins - Docker (2) Drone Plugins - Drone Buildah
  37. # 发布npm包到指定registry: Drone Plugins - NPM
  38. # 发布Python包到PyPi: Drone Plugins - PyPI
  39. # GitHub相关¶
  40. # 发布静态页面到GitHub: Drone Plugins - GitHub Pages
  41. # 发布新的Release到GitHub: Drone Plugins - Github Release
  42. # 生成ChangeLog: Drone Plugins - Github-changelog-generator
  43. # 发布Comment到GitHub的Pull Request: Drone Plugins - Github Comment
  44. # Gitea相关¶
  45. # 发布新的Release到Gitea: Drone Plugins - Gitea Release
  46. # 发布Comment到Gitea的Pull Request: Drone Plugins - Gitea Comment
  47. # 触发其他构建¶
  48. # 触发一组Drone下游构建: Drone Plugins - Downstream Build
  49. # 触发CircleCI构建: Drone Plugins - CircleCI
  50. # 触发GitlabCI构建: Drone Plugins - Gitlab-CI
  51. # 触发Jenkins构建: Drone Plugins - Jenkins
  52. # 消息通知¶
  53. # 发送Webhook消息: Drone Plugins - Webhook
  54. # 发送微信消息通知: Drone Plugins - Wechat
  55. # 发送企业微信消息通知: Drone Plugins - Wechat for Work
  56. # 发送邮件通知: Drone Plugins - Email
  57. # 发送丁丁消息通知: Drone Plugins - DingTalk
  58. # 发送及时达推送给微信用户通知: Drone Plugins - InstantAccess(即时达)
  59. # 发送Telegram消息通知: Drone Plugins - Telegram
  60. # 其他¶
  61. # 同步豆瓣标记的数据到csv、json或者Notion数据库: Drone Plugins - Doumark
  62. # 相关工具链¶
  63. # Testspace¶
  64. # 云托管测试: Test Management Software - Testspace
  65. # 在Drone中配置: CI/CD Support | Testspace
  66. # Codecov¶
  67. # 覆盖率检测: Codecov - The Leading Code Coverage Solution
  68. # 在Drone中配置: Drone Plugins - Codecov
  69. # Badge¶
  70. # 自定义Badge: Shields.io: Quality metadata badges for open source projects
  71. # 参考¶
  72. # Drone一直卡在pending状态FAQ: Builds are Stuck in Pending Status - FAQ - Drone
  73. # Drone插件市场: Drone Plugins
  74. # 插件开发: Overview | Drone
  75. #######################################################
  76. ###### steps : https://drone.cool/pipeline/docker/syntax/steps/
  77. #######################################################
  78. # step为执行的步骤,drone的步骤每一步都是使用临时docker的容器来实现的,每一步docker容器执行完会被自动销毁,所以本配置中的第一个用的是docker的ssh镜像,可以用来执行指定容器的命令。settings中配置了ssh要登录的host、username等,由于我们把username的信息放入drone来配置,这样保证了这些敏感字段的安全
  79. #- name: run-python
  80. # image: appleboy/drone-ssh
  81. # settings:
  82. # host: 192.168.1.246
  83. # username:
  84. # from_secret: pi_user
  85. # password:
  86. # from_secret: pi_password
  87. # port: 22
  88. # environment:
  89. # GOOS: linux
  90. # command_timeout: 5m
  91. # script:
  92. # - echo success
  93. # - cd /buildCache
  94. # - chmod 777 run.sh
  95. # - bash run.sh
  96. # 条件
  97. # when:
  98. # branch:
  99. # - master
  100. # when:
  101. # status:
  102. # - failure
  103. # - success
  104. # failure: ignore 失败后如何?
  105. #failure: ""
  106. #failure: "fail"
  107. #failure: "fail-fast"
  108. #failure: "fast"
  109. #failure: "always" #
  110. #failure: "ignore" # 单个失败,不影响整个 pipline
  111. #
  112. # detach: true # 后台异步执行,并且忽略其结果
  113. #
  114. # privileged: true 给容器赋予访问主机权限
  115. #
  116. # 任意阶段任意命令返回非0,则全部按照失败终止
  117. #######################################################
  118. ###### service : https://drone.cool/pipeline/docker/syntax/services/
  119. #######################################################
  120. #######################################################
  121. ###### plugins : https://plugins.drone.io/
  122. #######################################################
  123. # 比如单侧单独用 redis,这里可以异步起动一个服务,pipline完成后关闭
  124. #steps:
  125. #- name: ping
  126. # image: redis
  127. # commands:
  128. # - redis-cli -h cache ping
  129. #services:
  130. #- name: cache
  131. # image: redis
  132. ##################################### 编译 ##################################
  133. steps:
  134. - name: 编译
  135. image: maven:3-jdk-11
  136. pull: if-not-exists
  137. volumes:
  138. - name: mvnCache
  139. path: /root/.m2
  140. commands:
  141. - mvn compile -DskipTests=true -Dmaven.javadoc.skip=true -B -V
  142. - echo 'STATUS ALL FINISHED!'
  143. # - echo 'STATUS mvn package FINISHED!'
  144. # - cp xxxxx.jar unionbuildCache
  145. # - cp Dockerfile ...
  146. # - cp run.sh build/run.sh
  147. #- name: build-java-app
  148. # image: docker.io/kameshsampath/drone-java-maven-plugin:v1.0.0
  149. # pull: if-not-exists
  150. ##################################### quality ##################################
  151. # Sonar 代码质量,包含 FindBugs、PMD等
  152. # Fortity 代码安全扫描 收费
  153. # pom 漏洞扫描
  154. # SonarQube https://github.com/mibexsoftware/sonar-bitbucket-plugin
  155. # OWASP ZAP
  156. # Brakeman
  157. # CodeClimate
  158. # Coverity
  159. # Klocwork
  160. # PMD
  161. # SonarLint
  162. # FindBugs 官网 15年停更
  163. # 代码规范:Alibaba Java Coding Guidelines、checkStyle
  164. # https://juejin.cn/post/6844904018297225224
  165. #- name: sonar-scan
  166. # image: newtmitch/sonar-scanner:4.0.0-alpine
  167. # environment:
  168. # SONAR_TOKEN:
  169. # from_secret: sonar_token
  170. # GITHUB_ACCESS_TOKEN_FOR_SONARQUBE:
  171. # from_secret: github_access_token_for_sonarqube
  172. # commands:
  173. # - >
  174. # sonar-scanner
  175. # -Dsonar.host.url=https://sonarqube.company-beta.com/
  176. # -Dsonar.login=?SONAR_TOKEN
  177. # -Dsonar.projectKey=smcp-service-BE
  178. # -Dsonar.projectName=smcp-service-BE
  179. # -Dsonar.projectVersion=${DRONE_BUILD_NUMBER}
  180. # -Dsonar.sources=src/main/java
  181. # -Dsonar.tests=src/test/java
  182. # -Dsonar.language=java
  183. # -Dsonar.java.coveragePlugin=jacoco
  184. # -Dsonar.modules=smcp-api,smcp-web
  185. # -Dsonar.java.binaries=target
  186. # -Dsonar.projectBaseDir=.
  187. # -Dsonar.analysis.mode=preview
  188. # -Dsonar.github.repository=Today_Group/SMCP-Service
  189. # -Dsonar.github.oauth=?GITHUB_ACCESS_TOKEN_FOR_SONARQUBE
  190. # -Dsonar.github.pullRequest=${DRONE_PULL_REQUEST}
  191. # -Dsonar.github.disableInlineComments=false
  192. # when:
  193. # event:
  194. # - pull_request
  195. # branch:
  196. # - develop
  197. #
  198. # # post sonarscan result back to git PR (not in preview mode)
  199. # - name: sonar-scan-feedback
  200. # image: newtmitch/sonar-scanner:4.0.0-alpine
  201. # environment:
  202. # SONAR_TOKEN:
  203. # from_secret: sonar_token
  204. # GITHUB_ACCESS_TOKEN_FOR_SONARQUBE:
  205. # from_secret: github_access_token_for_sonarqube
  206. # commands:
  207. # - >
  208. # sonar-scanner
  209. # -Dsonar.host.url=https://sonarqube.company-beta.com/
  210. # -Dsonar.login=?SONAR_TOKEN
  211. # -Dsonar.projectKey=smcp-service-BE
  212. # -Dsonar.projectName=smcp-service-BE
  213. # -Dsonar.projectVersion=${DRONE_BUILD_NUMBER}
  214. # -Dsonar.sources=src/main/java
  215. # -Dsonar.tests=src/test/java
  216. # -Dsonar.language=java
  217. # -Dsonar.java.coveragePlugin=jacoco
  218. # -Dsonar.modules=smcp-api,smcp-web
  219. # -Dsonar.java.binaries=target
  220. # -Dsonar.projectBaseDir=.
  221. # -Dsonar.analysis.gitRepo=Today_Group/SMCP-Service
  222. # -Dsonar.analysis.pullRequest=${DRONE_PULL_REQUEST}
  223. # when:
  224. # event:
  225. # - pull_request
  226. # branch:
  227. # - develop
  228. ##################################### NOTIFY ####################################
  229. ---
  230. kind: pipeline
  231. type: docker
  232. name: notify
  233. # 以下内容不再需要clone代码
  234. clone:
  235. disable: true
  236. steps:
  237. - name: 钉钉通知
  238. image: guoxudongdocker/drone-dingtalk
  239. settings:
  240. token: 178f267b9b16b168e0a0afb223b3d41f3a58e62180ab5288aa576db02965dd72
  241. type: markdown
  242. #5f6c32b36e771df227b1ccb8898325158e12d851ae61982d1ec225a1aa58e251
  243. - name: dingtalk
  244. image: lddsb/drone-dingtalk-message
  245. settings:
  246. token: 178f267b9b16b168e0a0afb223b3d41f3a58e62180ab5288aa576db02965dd72
  247. type: markdown
  248. success_color: 008000
  249. failure_color: FF0000
  250. success_pic: http://82.157.141.169:16666/avatars/1
  251. msg_at_mobiles: 15858193327
  252. - name: email-notify
  253. image: drillster/drone-email
  254. settings:
  255. # true 只发送给指定邮件收件人 false: 只发给流水线触发人
  256. recipients_only: true
  257. recipients:
  258. from_secret: email_sender
  259. subject: "Drone build: [{{ build.status }}] {{ repo.name }} ({{ repo.branch }}) #{{ build.number }}"
  260. host: smtp.qq.com
  261. port: 465
  262. username:
  263. from_secret: email_sender
  264. password:
  265. from_secret: email_pwd
  266. from:
  267. from_secret: email_sender
  268. - name: wechat notify
  269. image: lizheming/drone-wechat
  270. settings:
  271. corpid: ww01cb42e24566126d
  272. corp_secret: un_CtWqThxc11MKWPK5SNWsFEgU9MkI7MIjvyvV9KjA
  273. agent_id: 1000002
  274. to_tag: ${DRONE_REPO_NAME}
  275. msg_url: ${DRONE_BUILD_LINK}
  276. safe: 1
  277. btn_txt: more
  278. title: ${DRONE_REPO_NAME}
  279. message: >
  280. {%if success %}
  281. build {{build.number}} succeeded. Good job.
  282. {% else %}
  283. build {{build.number}} failed. Fix me please.
  284. {% endif %}
  285. - name: wechat
  286. image: clem109/drone-wechat
  287. settings:
  288. corpid: ww01cb42e24566126d
  289. corp_secret: un_CtWqThxc11MKWPK5SNWsFEgU9MkI7MIjvyvV9KjA
  290. agent_id: 1000002
  291. title: ${DRONE_REPO_NAME}
  292. description: "Build Number: ${DRONE_BUILD_NUMBER} failed. ${DRONE_COMMIT_AUTHOR} please fix. Check the results here: ${DRONE_BUILD_LINK} "
  293. msg_url: ${DRONE_BUILD_LINK}
  294. btn_txt: bt
  295. #- name: webhook
  296. # image: plugins/webhook
  297. # settings:
  298. # username: myusername
  299. # password: mypassword
  300. # urls: https://oapi.dingtalk.com/robot/send?access_token=
  301. # content_type: application/json
  302. # template: |
  303. # {
  304. # "msgtype": "markdown",
  305. # "markdown": {
  306. # "content": "{{#success build.status}}✅{{else}}❌{{/success}}**{{ repo.owner }}/{{ repo.name }}** (Build #{{build.number}})\n
  307. # >**构建结果**: {{ build.status }}
  308. # >**构建详情**: [点击查看]({{ build.link }})
  309. # >**代码分支**: {{ build.branch }}
  310. # >**提交标识**: {{ build.commit }}
  311. # >**提交发起**: {{ build.author }}
  312. # >**提交信息**: {{ build.message }}
  313. # "
  314. # }
  315. # }
  316. volumes:
  317. - name: mvnCache
  318. host:
  319. path: /tmp/cache/.m2
  320. trigger:
  321. branch:
  322. - master
  323. event:
  324. - push
  325. # 构建完了在执行通知
  326. depends_on: [default]