
# 语法说明
基因容器语法，是GCS引以为傲的特性之一。使用基因容器语法编写的流程描述文件是基因容器服务流程控制的唯一方式。如已有其他流程语法文件，需要先转换为基因容器语法，然后才能由基因容器执行。流程描述文件的生成方式有多种，其一基于基因容器语法手动编写；其二是通过基因容器命令行自动生成；其三是使用流程设计器辅助编写；最后一种是通过流程迁移工具转换生成。当前仅支持前三种。
基因容器的流程描述语言支持YAML，YAML语法规则请参见[YAML语法](https://support.huaweicloud.com/tr-gcs/gcs_tr_01_0008.html)。为确保写作正确的基因容器语法，请先了解YAML语法规则。
为了简化语法，基因容器为流程语法提供了内置函数，提升GCS语法描述流程的能力。当前已支持的流程函数包括：
- [range](https://support.huaweicloud.com/tr-gcs/gcs_tr_03_0002.html)：用于任务并发时，迭代变量数量过多时，简化迭代变量范围。
- [get_result](https://support.huaweicloud.com/tr-gcs/gcs_tr_03_0003.html)：用于获取"指定步骤"的标准输出，生成控制当前任务并发的迭代变量范围。
- [check_result](https://support.huaweicloud.com/tr-gcs/gcs_tr_03_0004.html)：用于判断"指定步骤"的结果，是否等于预期值，从而决定是否执行当前步骤。
#### 模板结构
基因容器语法结构请参见[表1]。
 表1模板组成元素 
| 参数                                                                     | 是否必选 | 参数类型   | 参数描述                                 |
|:---|:---|:---|:---|
| [version](https://support.huaweicloud.com/tr-gcs/gcs_tr_01_0003.html)  | 是    | string | 流程文件的版本。当前支持为 **genecontainer_0_1**。 |
| [inputs](https://support.huaweicloud.com/tr-gcs/gcs_tr_01_0004.html)   | 否    | Map    | 整个流程的可变量。可以定义多个，在执行的时候设置这些变量的实际值。    |
| [workflow](https://support.huaweicloud.com/tr-gcs/gcs_tr_01_0005.html) | 是    | Map    | 定义完整流程包含的各个步骤，以及步骤之间的依赖关系。           |
| [volumes](https://support.huaweicloud.com/tr-gcs/gcs_tr_01_0006.html)  | 否    | Map    | 定义任务挂载共享存储的挂载路径。                     |
| [outputs](https://support.huaweicloud.com/tr-gcs/gcs_tr_01_0007.html)  | 否    | Map    | 定义流程最终生成的文件列表。用于界面展示使用。              |
   
#### 模板示例
```
version: genecontainer_0_1
inputs: #设置流程变量
  sample: #变量名
    default: sample1
    type: string
    description: 变量描述，支持中文
    label: basic
workflow: #设置流程顺序
  test-job-a:
    tool: busybox:latest
    type: GCS.Job
    resources:
      memory: 4G
    commands_iter: # {item} 为GCS内置变量，表示并发任务的 index，需要的时候选用
      command: sleep 10; touch /obs/test-job/${sample}.${item}.${1}.txt 
      vars_iter:
        - [0,1]
  test-job-b:
    tool: busybox:latest
    type: GCS.Job
    resources:
      memory: 4G
    commands:
      - sleep 10; touch /obs/test-job/${sample}.job-b.txt
    depends:
      - target: test-job-a #表示依赖另一个步骤，默认依赖类型: whole
volumes: #设置挂载共享存储
  genobs:
    mount_path: /obs
    mount_from:
      pvc: '${GCS_DATA_PVC}' #OBS数据桶
outputs: #设置最终结果
  result-txt: #结果文件
    paths_iter:
      path:  /obs/test-job/${sample}.${item}.${1}.txt
      vars_iter:
        - [0,1]
```
