示例 YAML 文件

你可以通过 UI 或使用仓库中的 YAML 文件(即 .rancher-pipeline.yml.rancher-pipeline.yaml)配置流水线。

流水线配置参考中,我们提供了使用 Rancher UI 或 YAML 来配置每个功能的示例。

以下是一个完整的 rancher-pipeline.yml 示例,供想要直接使用的用户使用:

  1. # 示例
  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. # 流水线的分支条件
  43. branch:
  44. include: [ master, feature/*]
  45. exclude: [ dev ]
  46. # 以分钟为单位的超时
  47. timeout: 30
  48. notification:
  49. recipients:
  50. - # Recipient
  51. recipient: "#mychannel"
  52. # Notifier 的 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"