.drone.yml 11 KB

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