YAML 文件示例

流水线(Pipelines)能够通过 Rancher UI 或者使用代码仓库中的 YMAL 文件,即 .rancher-pipeline.yml.rancher-pipeline.yaml 的方式进行配置。

流水线配置参考中,我们提供了通过 Rancher UI 或 YAML 来配置流水线的每个可用特性的示例。

这是一个完整的rancher-pipeline.yml示例供大家使用参考,适合那些想直接开始的用户。

  1. ## example
  2. stages:
  3. - name: Build something
  4. # 阶段条件
  5. when:
  6. branch: master
  7. event: [push, pull_request]
  8. # 多步骤同时运行
  9. steps:
  10. - runScriptConfig:
  11. image: busybox
  12. shellScript: echo ${FIRST_KEY} && echo ${ALIAS_ENV}
  13. # 该步骤为容器设置环境变量
  14. env:
  15. FIRST_KEY: VALUE
  16. SECOND_KEY: VALUE2
  17. # 设置导入项目密钥的环境变量
  18. envFrom:
  19. - sourceName: my-secret
  20. sourceKey: secret-key
  21. targetKey: ALIAS_ENV
  22. - runScriptConfig:
  23. image: busybox
  24. shellScript: date -R
  25. # 阶段条件
  26. when:
  27. branch: [master, dev]
  28. event: push
  29. - name: Publish my image
  30. steps:
  31. - publishImageConfig:
  32. dockerfilePath: ./Dockerfile
  33. buildContext: .
  34. tag: rancher/rancher:v2.0.0
  35. #(可选项)推送镜像到远程镜像库
  36. pushRemote: true
  37. registry: reg.example.com
  38. - name: Deploy some workloads
  39. steps:
  40. - applyYamlConfig:
  41. path: ./deployment.yaml
  42. ## Pipeline分支条件
  43. branch:
  44. include: [master, feature/*]
  45. exclude: [dev]
  46. ## 超时(单位:分钟)
  47. timeout: 30
  48. notification:
  49. recipients:
  50. - # 接收者
  51. recipient: "#mychannel"
  52. # 通知者ID
  53. notifier: "c-wdcsr:n-c9pg7"
  54. - recipient: "test@example.com"
  55. notifier: "c-wdcsr:n-lkrhd"
  56. # 选择您要发送通知的状态
  57. condition: ["Failed", "Success", "Changed"]
  58. #(可选项)覆盖默认消息
  59. message: "my-message"

Copy