YAML模板
YAML模板,也称为远程YAML定义,是带有可由流水线继承参数的模板。此功能对于快速设置新项目和一次性跨多个流水线更新配置很帮助。
要求与参数
- 一个文件等于一个模板。每个模板都需要在单独的文件中创建。
- 参数定义就像环境变量一样,但使用
!
代替$
,例如:!param1
- 在继承流水线中,您定义将交换为字符串参数。
- 您基本上可以参数化所有内容,从单个属性到整个操作。在下面的示例中,您可以看到两个参数:
!optionalaction
和!awsintegration
。
示例
- pipeline: "template"
on: "EVENT"
events:
- type: "PUSH"
refs:
- "refs/heads/development"
priority: "NORMAL"
fail_on_prepare_env_warning: true
actions:
- action: "pwd"
type: "BUILD"
working_directory: "/buddy/git-repo"
docker_image_name: "library/ubuntu"
docker_image_tag: "18.04"
execute_commands:
- "pwd"
volume_mappings:
- "/:/buddy/git-repo"
cache_base_image: true
shell: "BASH"
!optionalaction
- action: "cp bucket"
type: "AWS_CLI_2"
region: "us-east-1"
execute_commands:
- "aws s3 cp test.txt s3://mybucket/test2.txt"
shell: "SH"
integration_hash: "!awsintegration"
继承流水线配置
下一步是定义将从模板继承的流水线。在这些流水线中,您需要提供:
- 流水线名称
Definition_source: “REMOTE”
- 模板的项目、分支和路径
- 子流水线中要交换的参数列表
示例
- pipeline: "child1"
definition_source: "REMOTE"
remote_path: "/t1.yml"
remote_branch: "master"
remote_project_name: "templates"
remote_parameters:
- key: "optionalaction"
value: " - action: \"ls\"\n type: \"BUILD\"\n working_directory: \"/buddy/git-repo\"\n docker_image_name: \"library/ubuntu\"\n docker_image_tag: \"18.04\"\n execute_commands:\n - \"ls\"\n volume_mappings:\n - \"/:/buddy/git-repo\"\n cache_base_image: true\n shell: \"BASH\""
- key: "awsintegration"
value: "vVP4XgELYqaQ5Vg5anjk2m9Oz7"
- pipeline: "child2"
definition_source: "REMOTE"
remote_path: "/t1.yml"
remote_branch: "master"
remote_project_name: "templates"
remote_parameters:
- key: "optionalaction"
value: ""
- key: "awsintegration"
value: "vVP4XgELYqaQ5Vg5anjk2m9Oz7"
GUI配置
参数也可以从GUI界面定义。为此,在新添流水线时将配置模式切换为远程YAML,在文件系统中选择项目、分支和模板路径,并定义以下参数: