
# 创建流水线
#### 功能介绍
此API用于创建流水线。
#### URI
POST /cpepipeline/v2/pipelines
#### 请求消息
表1请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                                          |
|:---|:---|:---|:---|
| Content-Type | 是    | String | 消息体的类型（格式），默认取值为"application/json;charset=utf8"。                                                                                            |
| X-Auth-Token | 是    | String | 调用接口的认证方式分为Token和AK/SK两种，如果您使用的Token方式，此参数为必填，请填写Token的值。Token获取方式，请参考[获取用户Token](https://support.huaweicloud.com/api-iam/iam_30_0001.html) |
   
表2请求Body参数 
| 参数           | 是否必选 | 参数类型             | 描述                                                         |
|:---|:---|:---|:---|
| name         | 是    | String           | 流水线名称。                                                     |
| description  | 否    | String           | 流水线描述。                                                     |
| version      | 否    | Integer          | 流水线版本。                                                     |
| stages       | 是    | Array of objects | 阶段，详情请见[表3]。   |
| environments | 否    | Array of objects | 发布环境，详情请见[表3]。 |
   
 表3stages and environments 
| 参数           | 是否必选 | 参数类型             | 描述                                                      |
|:---|:---|:---|:---|
| name         | 是    | String           | 阶段名称/发布环境名称。                                            |
| approvalType | 是    | Integer          | 审批类型。                                                   |
| description  | 否    | String           | 描述。                                                     |
| tasks        | 是    | Array of objects | 任务，详情请见[表4]。 |
   
 表4tasks 
| 参数          | 是否必须 | 参数类型    | 描述                                                         |
|:---|:---|:---|:---|
| name        | 是    | String  | 任务名称。                                                      |
| displayName | 是    | String  | 显示名称                                                       |
| input       | 否    | Object  | 输入参数，详情请见[表5]。   |
| taskTypeId  | 是    | Object  | 任务类型参数，详情请见[表6]。 |
| orderIndex  | 否    | Integer | 任务执行顺序。                                                    |
| output      | 否    | Object  | 输出参数。                                                      |
   
 表5input 
| 参数           | 是否必选 | 参数类型   | 描述      |
|:---|:---|:---|:---|
| assemblingId | 否    | String | 构建任务ID。 |
| instanceId   | 否    | String | 实例ID。   |
| appName      | 否    | String | 应用名称。   |
| modifiedPath | 否    | String | 修改路径。   |
| version      | 否    | String | 组件版本    |
   
 表6taskTypeId 
| 参数       | 是否必须 | 参数类型   | 描述     |
|:---|:---|:---|:---|
| category | 是    | String | 任务目录。  |
| owner    | 是    | String | 任务所有者。 |
| provider | 是    | String | 任务提供方。 |
   
#### 响应消息
表7响应参数 
| 参数                  | 参数类型    | 描述                                                         |
|:---|:---|:---|
| project             | String  | 项目名称。                                                      |
| domain              | String  | 租户名称。                                                      |
| id                  | String  | 流水线ID。                                                     |
| enterpriseProjectId | String  | 企业项目ID。                                                    |
| modelVersion        | Integer | 流水线类型。                                                     |
| creator             | String  | 创建者。                                                       |
| revisor             | String  | 修订者。                                                       |
| createdAt           | Integer | 创建时间。                                                      |
| createdAt           | Integer | 修改时间。                                                      |
| failMode            | String  | 激进策略。                                                      |
| strategyType        | Integer | 触发策略。                                                      |
| pipelineDeclaration | Object  | 流水线定义，详情请见[表8]。 |
   
 表8pipelineDeclaration 
| 参数           | 参数类型             | 描述                                                         |
|:---|:---|:---|
| name         | String           | 流水线名称                                                      |
| modelVersion | Integer          | 流水线类型。                                                     |
| version      | Integer          | 流水线版本。                                                     |
| stages       | Array of objects | 流水线阶段，详情请见[表9]。 |
| configMode   | String           | 流水线创建类型。                                                   |
   
 表9stages 
| 参数          | 参数类型             | 描述                                                         |
|:---|:---|:---|
| id          | String           | 阶段ID。                                                      |
| name        | String           | 阶段名称。                                                      |
| displayName | String           | 阶段显示名称。                                                    |
| type        | String           | 阶段类型。                                                      |
| pipelineId  | String           | 流水线ID。                                                     |
| orderIndex  | String           | 阶段执行顺序。                                                    |
| status      | Integer          | 阶段状态。                                                      |
| taskGroup   | String           | 任务组。                                                       |
| tasks       | Array of objects | 流水线任务，详情请见[表10]。 |
   
 表10tasks 
| 参数           | 参数类型    | 描述                                                          |
|:---|:---|:---|
| id           | Integer | 任务ID。                                                       |
| name         | String  | 任务名称。                                                       |
| displayName  | String  | 任务显示名称。                                                     |
| input        | Object  | 任务输入参数，详情请见[表5]。  |
| output       | Object  | 任务输出参数                                                      |
| status       | Integer | 任务状态。                                                       |
| orderIndex   | Integer | 任务执行顺序。                                                     |
| skipped      | Boolean | 是否跳过。                                                       |
| groupIndex   | String  | 任务所在任务组。                                                    |
| delayTime    | Integer | 任务延迟执行时间。                                                   |
| errorDetails | String  | 任务报错信息。                                                     |
| stageName    | String  | 阶段类型。                                                       |
| taskTypeId   | Object  | 任务类型参数，详情请见[表11]。 |
   
 表11taskTypeId 
| 参数       | 参数类型   | 描述     |
|:---|:---|:---|
| category | String | 任务目录。  |
| owner    | String | 任务所有者。 |
| provider | String | 任务提供方。 |
| type     | String | 任务类型。  |
   
表12input 
| 参数             | 参数类型   | 描述      |
|:---|:---|:---|
| assemblingId   | String | 构建任务ID。 |
| environment_id | String | 环境ID。   |
   
#### 请求示例
创建流水线
```
{
    "name": "asdxad",
    "description": "",
    "version": 1,
    "stages": [
        {
            "name": "Artifacts",
            "approvalType": 0,
            "tasks": [
                {
                    "name": "ghy-test-comp-0626-3-62e353",
                    "displayName": "Empty",
                    "input": {
                        "assemblingId": "audzvfrtnru94o8jtb9g38svx0rezi86rq43ff8m"
                    },
                    "taskTypeId": {
                        "category": "Build",
                        "owner": "System",
                        "provider": "Assembling"
                    },
                    "orderIndex": 0
                }
            ]
        },
        {
            "name": "Environments",
            "approvalType": 0,
            "tasks": [
                {
                    "name": "production",
                    "displayName": "echotest-nodel",
                    "orderIndex": 0,
                    "taskTypeId": {
                        "category": "Environment",
                        "owner": "System",
                        "provider": "Environment"
                    },
                    "input": {},
                    "output": {}
                }
            ]
        }
    ],
    "environments": [
        {
            "name": "production",
            "displayName": "echotest-nodel",
            "description": "",
            "tasks": [
                {
                    "name": "Deploy",
                    "taskTypeId": {
                        "category": "Deploy",
                        "owner": "System",
                        "provider": "ENV-CAS"
                    },
                    "input": {
                        "instanceId": "9c1fa25d-7e5a-4de4-bf3a-516b9650c2a0",
                        "appName": "ghy-test-0710-1",
                        "modifiedPath": "{\"ghy-test-0710-1\":\"${Artifacts_ghy-test-comp-0626-3-62e353_Output_release@PublishBuildImage}\"}",
                        "version": "2025.0710.11521"
                    },
                    "output": {},
                    "orderIndex": 0
                }
            ]
        }
    ]
}
```
#### 响应示例
```
{
    "project": "cn-north-4",
    "domain": "hwstaff_pub_servicestagew3",
    "id": "c5a2abab-6c56-4b04-bb67-92470daef78f",
    "enterpriseProjectId": "0",
    "name": "testzasd",
    "enterpriseProject": "default",
    "modelVersion": 1,
    "creator": "zhangyuhao",
    "revisor": "zhangyuhao",
    "createdAt": 1753080263966,
    "updatedAt": 1753080263966,
    "failMode": "stop",
    "strategyType": 0,
    "pipelineDeclaration": {
        "name": "testzasd",
        "description": "",
        "modelVersion": 0,
        "version": 1,
        "stages": [
            {
                "id": 0,
                "name": "Artifacts",
                "approvalType": 0,
                "displayName": null,
                "type": null,
                "pipelineId": null,
                "orderIndex": 0,
                "status": null,
                "taskGroup": null,
                "tasks": [
                    {
                        "id": 0,
                        "name": "ghy-test-comp-0626-3-62e353",
                        "displayName": "Empty",
                        "taskTypeId": {
                            "category": "Build",
                            "owner": "System",
                            "provider": "Assembling",
                            "type": null
                        },
                        "input": {
                            "assemblingId": "audzvfrtnru94o8jtb9g38svx0rezi86rq43ff8m"
                        },
                        "output": {},
                        "status": null,
                        "orderIndex": 0,
                        "skipped": false,
                        "groupIndex": null,
                        "delayTime": 0,
                        "errorDetails": null,
                        "stageName": null
                    }
                ]
            },
            {
                "id": 0,
                "name": "Environments",
                "approvalType": 0,
                "displayName": null,
                "type": null,
                "pipelineId": null,
                "orderIndex": 0,
                "status": null,
                "taskGroup": null,
                "tasks": [
                    {
                        "id": 0,
                        "name": "production",
                        "displayName": "echotest-nodel",
                        "taskTypeId": {
                            "category": "Environment",
                            "owner": "System",
                            "provider": "Environment",
                            "type": null
                        },
                        "input": {
                            "environment_id": "6a67914f-8233-4a62-bd7c-5905bfde5df8"
                        },
                        "output": {},
                        "status": null,
                        "orderIndex": 0,
                        "skipped": false,
                        "groupIndex": null,
                        "delayTime": 0,
                        "errorDetails": null,
                        "stageName": null
                    }
                ]
            }
        ],
        "configMode": "ui"
    }
}
```
#### 状态码
| 状态码 | 描述     |
|:---|:---|
| 200 | 操作成功。  |
| 400 | 错误的请求。 |
   
#### 错误码
请参考[ServiceStage错误码](https://support.huaweicloud.com/api-servicestage/servicestage_06_0162.html)。
