跳到主要内容

YAML构架

详细了解Buddy中流水线和操作的架构

buddy.yml 文件定义了项目中的所有流水线,每个流水线都包含要执行的操作列表,您将在下面找到流水线和操作的模式。

流水线构架

该文件由一系列流水线组成:

- pipeline: "production"
on: "CLICK"
refs:
- "refs/heads/master"
variables:
- key: "username"
value: "Buddy"
settable: false
description: "var_descrption"
- pipeline: "build"
on: "EVENT"
events:
- type: "PUSH"
refs:
- "*"

属性

名称类型描述
pipeline
必填
String流水线ID
on
必填
String流水线触发模式:CLICK(手动)、 EVENT(事件/自动)、 SCHEDULE(定时/周期)
refsString[]Set it if on is set to CLICK or SCHEDULE. The list of refs for which the pipeline will be triggered. Automatically set to NONE if not provided.
eventsEvent[]The list of events for which the pipeline will be triggered. Set it if on is set to EVENT.
trigger_conditionsTriggerCondition[]The list of trigger conditions to meet so that the pipeline can be triggered.
always_from_scratchBooleanDefines whether or not to upload everything from scratch on every execution.
auto_clear_cacheBooleanDefines whether or not to automatically clear cache before running the pipeline .
no_skip_to_most_recentBooleanDefines whether or not to skip execution to the most recent execution.
do_not_create_commit_statusBooleanDefines whether or not to omit sending commit statuses to Github or Gitlab upon execution.
start_dateiso 8601 utc dateRequired if the pipeline is set to on: SCHEDULE and no cron is specified. Defines when the pipeline execution should start. Format: 2016-11-18T12:38:16.000Z
delayIntegerRequired if the pipeline is set to on: SCHEDULE and no cron is specified. Defines the intervals in which the pipeline should be executed (in minutes).
cronStringRequired if the pipeline is set to on: SCHEDULE and neither start_date nor delay is specified. The standard CRON expression defining the execution schedule.
actionsAction[]The list of actions executed in the pipeline.
variablesVariable[]The list of variables you can use in the pipeline.
ignore_fail_on_project_statusBooleanIf set to true the status of a given pipeline will not impact the project status on the dashboard.
execution_message_templateStringThe title of every execution in this pipeline. By default it is set to $BUDDY_EXECUTION_REVISION_SUBJECT.
worker_assignmentStringDefines the worker assignment method. Can be one of FIXED or TAGS. Only for Buddy On-Premises. Read here for more details.
workerStringDefines the worker on which the pipeline runs when worker_assignment is set to FIXED. Only for Buddy On-Premises.
target_site_urlStringThe URL of the target website.
disabledBooleanSet it, if you want the pipeline to be disabled
disabled_reasonStringSpecify the reason for disabling the pipeline

操作构架

每个流水线都包含一个操作列表。这些操作按照 .yml 文件中提供的顺序执行:

- pipeline: "production"
on: "CLICK"
refs:
- "refs/heads/master"
execution_message_template: "test"
ignore_fail_on_project_status: "true"
actions:
- action: "Execute: npm test"
type: "BUILD"
docker_image_name: "library/node"
docker_image_tag: "6"
execute_commands:
- "npm install"
- "npm test"
setup_commands:
- "npm install -g gulp grunt-cli"
variables:
- key: "username"
value: "Buddy"
settable: true
description: "var_description"
retry_interval: 1
retry_count: 3
- action: "Upload files to buddy.server"
type: "FTP"
input_type: "BUILD_ARTIFACTS"
local_path: "/"
login: "buddy"
password: "password"
host: "buddy.server"
port: "21"
retry_interval: 1
retry_count: 3

属性

名称类型描述
action
必填
String操作ID
type
必填
String操作类型
variablesVariable[]您可以使用操作的变量列表
trigger_conditionsTriggerCondition[]满足条件才能触发操作的[触发条件列表
timeoutIntegerThe timeout in seconds.
disabledBooleanWhen set to true the action is disabled. By default it is set to false.
run_next_parallelBooleanWhen set to true, the subsequent action defined in the pipeline will run in parallel to the current action.
run_only_on_first_failureBooleanDefines whether the action should be executed on each failure. Restricted to and required if the trigger_time is ON_FAILURE.
ignore_errorsBooleanIf set to true the execution will proceed, mark action as a warning and jump to the next action. Doesn't apply to deployment actions.
retry_intervalIntegerDelay time between auto retries in seconds.
retry_countIntegerNumber of retries if the action fails.
信息

On top of these properties every action has a set properties unique to its type. You can read how to define each type of action in separate articles.

变量构架

您可以通过以下方式定义变量:

variables:
- key: "my_file"
type: "FILE"
value: "dGVzdA0K"
file_name: "file"
file_path: "/buddy-variables/file"
file_chmod: "644"
file_place: "CONTAINER"
- key: "id_my_key"
value: "secure!xgXxzMBVkpGEp4sRMxUIEL4TFQSZQv6PklzVGeRYPLOKYR/nNXTTKzYABWNGSgFZenjhGy5sMu8SBEDZAsZI9I188jdF3x5cHkxzq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iylAVf8oeD57u9w=="
type: "SSH_KEY"
encrypted: true
file_name: "id_my_key"
file_path: "~/.ssh/id_my_key"
file_chmod: "600"
file_place: "CONTAINER"
- key: "my_variable"
value: "my_value"
type: "VAR"

属性

名称类型描述
key
必填
StringThe name of the variable.
value
必填
StringThe value of the variable. If the type is FILE, the value must be Base64 encoded.
typeStringThe type of the added variable. Can be one of VAR, SSH_KEY or FILE.
descriptionStringThe optional description of the variable.
encryptedBooleanWhen set to true the variable value will be encrypted and hidden.
settableBooleanWhen set to true the variable value can be shifted between subsequent actions or executions as well as pipelines.
file_placeStringAvailable values: CONTAINER, NONE. Set if type is SSH_KEY or FILE. If it's NONE, the variable can be used as a parameter in an action. For CONTAINER, the given file/key is additionally copied to an action container on each run.
file_nameStringThe name of the file. Set if type is SSH_KEY or FILE.
file_pathStringSpecifies where to copy the file on each run. Set if type is SSH_KEY or FILE.
file_chmodStringFile permission set on copy to a container on each run. Set if type is SSH_KEY or FILE.

通过Buddy加密工具在YAML中使用加密变量

使用加密值定义变量:

  1. 进入“项目设置” -> "YAML工具" -> "为YAML加密敏感值": Generating a new encrypted value

  2. 提供输入值并单击加密。它将生成一个哈希值,您可以在YAML中复制并安全地使用该哈希值: Setting a new encrypted value

提醒

用于加密值的盐对于每个工作区都是唯一的。如果您更改它,您将需要更改YAML中的所有加密值。

仅当您使用导出/导入选项将流水线移动到另一个工作区或从云服务移动到自托管版本时,才应更改该值。

事件构架

以下是定义触发流水线事件/自动的方法:

events:
- type: "PUSH"
refs:
- "refs/heads/master"
- "refs/heads/dev-*

属性

名称类型描述
type
必填
StringThe type of the event. Available values: PUSH, CREATE_REF, DELETE_REF.
refs
必填
String[]The list of refs for which the pipeline will be triggered in the given event.

触发条件构架

您可以通过以下方式定义触发条件:

 trigger_conditions:
- trigger_condition: "VAR_IS"
trigger_variable_value: "expectedValue"
trigger_variable_key: "myVar"
- trigger_condition: "ON_CHANGE"

属性

名称类型描述
trigger_conditionStringDefines when the build action should be run. Can be one of ALWAYS, ON_CHANGE, ON_CHANGE_AT_PATH, VAR_IS, VAR_IS_NOT, VAR_CONTAINS, VAR_NOT_CONTAINS, DATETIME or SUCCESS_PIPELINE. Can't be used in deployment actions.
trigger_condition_pathsString[]Required when trigger_condition is set to ON_CHANGE_AT_PATH.
trigger_variable_keyStringRequired when trigger_condition is set to VAR_IS, VAR_IS_NOT or VAR_CONTAINS or VAR_NOT_CONTAINS. Defines the name of the desired variable.
trigger_variable_valueStringRequired when trigger_condition is set to VAR_IS, VAR_IS_NOT or VAR_CONTAINS or VAR_NOT_CONTAINS. Defines the value of the desired variable which will be compared with its current value.
trigger_hoursInteger[]Available when trigger_condition is set to DATETIME. Defines the time – by default running from 1 to 24.
trigger_daysInteger[]Available when trigger_condition is set to DATETIME. Defines the days running from 1 to 7 where 1 is for Monday.
zone_idStringAvailable when trigger_condition is set to DATETIME. Defines the timezone (by default it is UTC) and takes values from here.
trigger_project_nameStringRequired when trigger_condition is set to SUCCESS_PIPELINE. Defines the name of the project in which the trigger_pipeline_name is.
trigger_pipeline_nameStringRequired when trigger_condition is set to SUCCESS_PIPELINE. Defines the name of the pipeline.

工作器分配构架

信息

将流水线分配给工作器是Buddy自托管独有的功能。阅读此文了解更多信息>>>

此为定义流水线工作器分配标准的方式:

  tags:
- "tag1"
- "tag2"
worker_assignment: "TAGS"
worker: "worker-4"

属性

名称类型描述
worker_assignmentStringDefines the worker assignment method. Can be one of FIXED or TAGS. When set to FIXED, the worker is assigned in the worker property.
tagsString[]Required when worker_assignment is set to TAGS. Runs the pipeline on the worker with tags that match those specified in the array.
workerStringDefines the worker on which the pipeline runs when worker_assignment is set to FIXED. If you don't specify the worker, Buddy automatically runs the pipeline on the main worker of the On-Premises instance.

多行YAML

要在YAML中应用多行,请使用 |(竖线)符:

pipeline: |
first line
second line

请注意,某些字段是集合,应保留集合结构。这适用于SSH和构建操作:

 - action: "Execute: ls"
type: "BUILD"
execute_commands:
- npm install
- npm test
- npm build

如果要在此类操作中应用多行执行命令,则需要将其定义为 execute_commands 集合的元素:

 - action: "Execute: ls"
type: "BUILD"
execute_commands:
- |
npm install &&
npm test
- npm build