
# 流水线上下文
#### 什么是流水线上下文
流水线上下文是指在流水线运行过程中，用于存储和传递与流水线相关的各种信息的一种机制或环境。流水线上下文存储了流水线运行的实例、变量、任务等信息，每个上下文都是一个包含各种属性的对象。使用流水线时，当一个任务生成了数据或结果，且这些数据或结果需要在后续的任务中使用时，可以基于流水线上下文来实现，流水线上下文可以帮助实现任务间的信息传递和协作，使得整个流水线运作更加灵活和高效。流水线上下文主要包括以下四类：
表1流水线上下文 
| **上下文**  | **类型** | **说明**               |
|:---|:---|:---|
| pipeline | object | 流水线运行相关的信息。          |
| sources  | object | 流水线运行的源相关的信息。        |
| env      | object | 流水线运行的自定义参数相关的信息。    |
| jobs     | object | 流水线运行的已执行完成的任务相关的信息。 |
   
#### 流水线上下文引用形式
```
${{ <context>.<attribute_name> }}
```
- context：流水线上下文。
- attribute_name：属性。
 
#### 流水线上下文属性介绍
表2流水线上下文属性 
| **上下文**          | 属性                                      | **类型** | **说明**                                                                                                                                                                                  | **示例**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
|:---|:---|:---|:---|:---|
| pipeline context | pipeline                                | object | 流水线运行相关的所有信息，此对象包含的属性包括：project_id、pipeline_id、run_number、timestamp、trigger_type和run_id。                                                                                                | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.project_id                     | string | 当前流水线所属项目ID，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)PROJECT_ID。                                | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.component_id                   | string | 当前流水线所属微服务ID，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)COMPONENT_ID。                             | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.pipeline_id                    | string | 当前流水线ID，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)PIPELINE_ID。                                   | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.run_number                     | string | 流水线执行编号，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)PIPELINE_NUMBER。                               | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.timestamp                      | string | 流水线执行时间戳，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)TIMESTAMP，格式为yyyyMMddHHmmss。如：20211222124301。 | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.trigger_type                   | string | 流水线触发类型，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)PIPELINE_TRIGGER_TYPE。                         | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.run_id                         | string | 流水线执行ID，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)PIPELINE_RUN_ID。                               | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.execute_user_name              | string | 流水线执行人名称，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)EXECUTE_USER_NAME。                            | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.external_system                | string | 触发流水线的外部系统，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)EXTERNAL_SYSTEM。**该参数只在流水线被外部系统触发时才出现。**    | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.external_user_id               | string | 外部系统触发流水线时的用户ID，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)EXTERNAL_USER_ID。                      | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.external_user_name             | string | 外部系统触发流水线时的用户名称，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)EXTERNAL_USER_NAME。                    | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| pipeline context | pipeline.upstream_status                | string | 流水线除后处理阶段外的前置阶段的状态。                                                                                                                                                                     | - 内容示例 如下示例为一次手动运行的流水线包含的pipeline context信息。 ``` { "project_id": "6428c2e2b4b64affa14ec80896695c49", "pipeline_id": "f9981060660249a3856f46c2c402f244", "run_number": "168", "timestamp": "20231016000004", "trigger_type": "Manual", "run_id": "c2f507f93510459190b543e47f6c9bec" } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的触发方式，可使用如下语法来获取。 ``` ${{ pipeline.trigger_type }} ```                                                                                                                               |
| sources context  | sources                                 | object | 流水线运行的源相关的所有信息，此对象包含的属性包括：alias、repo_name、commit_id、commit_id_short、commit_message、repo_url、repo_type、ssh_repo_url、tag、merge_id、source_branch和target_branch。                            | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>                       | object | 别名为alias对应的流水线源的所有信息，当流水线源定义别名时存在。                                                                                                                                                      | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<repo_name\>                   | object | 代码仓名称为repo_name的流水线代码源的所有信息，当代码源未定义别名时存在，包含属性同alias。                                                                                                                                    | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>.commit_id             | string | 流水线执行前最后一次代码提交的CommitID，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)COMMIT_ID。                     | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>.commit_id_short       | string | 流水线执行前最后一次代码提交的CommitID的前8位，同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)COMMIT_ID_SHORT。           | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>.commit_message        | string | 流水线执行前最后一次代码提交的提交信息。                                                                                                                                                                    | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>.repo_url              | string | 代码仓地址（HTTPS），同现有[流水线系统预定义参数](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0003.html#pipeline_01_0003__section1040118518917)REPO_URL。                                 | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>.repo_type             | string | 代码仓类型。如：codehub、gitlab、github、gitee、general_git。                                                                                                                                        | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>.repo_name             | string | 代码仓名称。                                                                                                                                                                                  | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>.ssh_repo_url          | string | 代码仓地址（SSH）。                                                                                                                                                                             | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>.tag                   | string | 标签触发时的标签名称。                                                                                                                                                                             | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>.merge_id              | string | 合并请求触发时的合并请求ID。                                                                                                                                                                         | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>.source_branch         | string | 合并请求触发时的源分支名称。                                                                                                                                                                          | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| sources context  | sources.\<alias\>.target_branch         | string | MR时代表目标分支名称，否则代表运行分支名称。                                                                                                                                                                 | - 内容示例 如下示例为单代码源的流水线一次手动运行所包含的sources context信息，其中代码源别名为"my_repo"。 ``` { "my_repo": { "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc", "commit_id_short": "dedb73bb", "commit_message": "maven0529 更新 pipeline0615.yml", "repo_url": "https://example.com/clsyz00001/maven0529.git", "repo_type": "codehub", "repo_name": "maven0529", "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git", "target_branch": "master" } } ```   - 使用示例 如需在某个任务的输入中获取本次流水线运行的运行分支，可使用如下语法来获取。 ``` ${{ sources.my_repo.target_branch }} ```    |
| env context      | name                                    | string | 自定义参数名称。                                                                                                                                                                                | - 内容示例 如下示例为流水线一次运行包含的env context信息，包含了两个自定义参数。 ``` { "var_1": "val1", "var_2": "val2" } ```   - 使用示例 如需要在某个任务的输入中获取本次流水线运行的自定义参数"var_1"的值，可使用如下语法来获取。 ``` ${{ env.var_1 }} ```                                                                                                                                                                                                                                                                                                                                                                     |
| env context      | value                                   | string | 自定义参数值。                                                                                                                                                                                 | - 内容示例 如下示例为流水线一次运行包含的env context信息，包含了两个自定义参数。 ``` { "var_1": "val1", "var_2": "val2" } ```   - 使用示例 如需要在某个任务的输入中获取本次流水线运行的自定义参数"var_1"的值，可使用如下语法来获取。 ``` ${{ env.var_1 }} ```                                                                                                                                                                                                                                                                                                                                                                     |
| jobs context     | jobs                                    | object | 流水线运行的任务相关的信息，此对象包含的属性包括： job_id、status、outputs、output_name、metrics、metric_name。                                                                                                        | - 内容示例 如下示例为流水线一次运行对应的jobs context信息，包含两个执行成功的任务，ID为"check_job"的任务的输出为两项指标，ID为"demo_job"的任务的输出为两项一般输出。 ``` { "check_job": { "status": "COMPLETED", "metrics": { "critical": "0", "major": "0" } }, "demo_job": { "status": "COMPLETED", "outputs": { "output1": "val1", "output2": "val2" } } } ```   - 使用示例 如需要在后续任务的输入中获取本次运行的"demo_job"的输出"output1"的值，可使用如下语法来获取。 ``` ${{ jobs.demo_job.outputs.output1 }} ```                                                                                                                         |
| jobs context     | jobs.\<job_id\>                         | object | ID为job_id的任务包含的所有信息。                                                                                                                                                                    | - 内容示例 如下示例为流水线一次运行对应的jobs context信息，包含两个执行成功的任务，ID为"check_job"的任务的输出为两项指标，ID为"demo_job"的任务的输出为两项一般输出。 ``` { "check_job": { "status": "COMPLETED", "metrics": { "critical": "0", "major": "0" } }, "demo_job": { "status": "COMPLETED", "outputs": { "output1": "val1", "output2": "val2" } } } ```   - 使用示例 如需要在后续任务的输入中获取本次运行的"demo_job"的输出"output1"的值，可使用如下语法来获取。 ``` ${{ jobs.demo_job.outputs.output1 }} ```                                                                                                                         |
| jobs context     | jobs.\<job_id\>.status                  | string | 任务的运行结果，取值结果为：INIT（初始化）、QUEUED（排队中）、RUNNING（运行中）、CANCELED（已中止）、COMPLETED（成功）、FAILED（失败）、PAUSED（暂停）、IGNORED（忽略）、SUSPEND（挂起）或UNSELECTED（未选择）。                                             | - 内容示例 如下示例为流水线一次运行对应的jobs context信息，包含两个执行成功的任务，ID为"check_job"的任务的输出为两项指标，ID为"demo_job"的任务的输出为两项一般输出。 ``` { "check_job": { "status": "COMPLETED", "metrics": { "critical": "0", "major": "0" } }, "demo_job": { "status": "COMPLETED", "outputs": { "output1": "val1", "output2": "val2" } } } ```   - 使用示例 如需要在后续任务的输入中获取本次运行的"demo_job"的输出"output1"的值，可使用如下语法来获取。 ``` ${{ jobs.demo_job.outputs.output1 }} ```                                                                                                                         |
| jobs context     | jobs.\<job_id\>.outputs                 | object | 任务的运行一般输出，即键值对形式的数据输出。                                                                                                                                                                  | - 内容示例 如下示例为流水线一次运行对应的jobs context信息，包含两个执行成功的任务，ID为"check_job"的任务的输出为两项指标，ID为"demo_job"的任务的输出为两项一般输出。 ``` { "check_job": { "status": "COMPLETED", "metrics": { "critical": "0", "major": "0" } }, "demo_job": { "status": "COMPLETED", "outputs": { "output1": "val1", "output2": "val2" } } } ```   - 使用示例 如需要在后续任务的输入中获取本次运行的"demo_job"的输出"output1"的值，可使用如下语法来获取。 ``` ${{ jobs.demo_job.outputs.output1 }} ```                                                                                                                         |
| jobs context     | jobs.\<job_id\>.outputs.\<output_name\> | string | 任务的运行一般输出的数据名称。                                                                                                                                                                         | - 内容示例 如下示例为流水线一次运行对应的jobs context信息，包含两个执行成功的任务，ID为"check_job"的任务的输出为两项指标，ID为"demo_job"的任务的输出为两项一般输出。 ``` { "check_job": { "status": "COMPLETED", "metrics": { "critical": "0", "major": "0" } }, "demo_job": { "status": "COMPLETED", "outputs": { "output1": "val1", "output2": "val2" } } } ```   - 使用示例 如需要在后续任务的输入中获取本次运行的"demo_job"的输出"output1"的值，可使用如下语法来获取。 ``` ${{ jobs.demo_job.outputs.output1 }} ```                                                                                                                         |
| jobs context     | jobs.\<job_id\>.metrics                 | object | 任务的运行指标输出。如：代码检查问题数、测试通过率等指标项。                                                                                                                                                          | - 内容示例 如下示例为流水线一次运行对应的jobs context信息，包含两个执行成功的任务，ID为"check_job"的任务的输出为两项指标，ID为"demo_job"的任务的输出为两项一般输出。 ``` { "check_job": { "status": "COMPLETED", "metrics": { "critical": "0", "major": "0" } }, "demo_job": { "status": "COMPLETED", "outputs": { "output1": "val1", "output2": "val2" } } } ```   - 使用示例 如需要在后续任务的输入中获取本次运行的"demo_job"的输出"output1"的值，可使用如下语法来获取。 ``` ${{ jobs.demo_job.outputs.output1 }} ```                                                                                                                         |
| jobs context     | jobs.\<job_id\>.metrics.\<metric_name\> | string | 任务的运行指标输出的名称。                                                                                                                                                                           | - 内容示例 如下示例为流水线一次运行对应的jobs context信息，包含两个执行成功的任务，ID为"check_job"的任务的输出为两项指标，ID为"demo_job"的任务的输出为两项一般输出。 ``` { "check_job": { "status": "COMPLETED", "metrics": { "critical": "0", "major": "0" } }, "demo_job": { "status": "COMPLETED", "outputs": { "output1": "val1", "output2": "val2" } } } ```   - 使用示例 如需要在后续任务的输入中获取本次运行的"demo_job"的输出"output1"的值，可使用如下语法来获取。 ``` ${{ jobs.demo_job.outputs.output1 }} ```                                                                                                                         |
   
#### 相关信息
流水线上下文应用广泛，以下常见场景供参考：
- [配置流水线执行条件表达式](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0006.html)。
- [配置通过流水线上下文获取构建任务的产物信息](https://support.huaweicloud.com/usermanual-pipeline/pipeline_01_0008.html)。
- [通过流水线生成标签名并通过上下文传递为代码仓库创建标签](https://support.huaweicloud.com/bestpractice-pipeline/pipeline_practice_0014.html)。
 
