
# 创建流水线 - CreatePipelineNew
#### 功能介绍
创建流水线
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-pipeline/pipeline_03_0006.html)。
#### URI
POST /v5/{project_id}/api/pipelines
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                             |
|:---|:---|:---|:---|
| project_id | 是    | String | **参数解释**： 项目ID，获取方式请参见[获取项目ID](https://support.huaweicloud.com/api-pipeline/pipeline_03_0036.html)。 **约束限制**： 不涉及。 **取值范围**： 32位字符，由数字和字母组成。 **默认取值**： 不涉及。 |
   
表2Query参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                      |
|:---|:---|:---|:---|
| component_id | 否    | String | **参数解释**： 微服务ID。可以通过[查询微服务列表](https://support.huaweicloud.com/api-pipeline/ListMicroservice.html)接口获取，其中data.id即为微服务ID。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。 |
   
#### 请求参数
表3请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                             |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | **参数解释**： 用户Token。通过调用[IAM服务获取用户Token接口](https://support.huaweicloud.com/api-iam/iam_30_0003.html)获取（响应消息头中X-Subject-Token的值）。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。 |
   
表4请求Body参数 
| 参数                  | 是否必选 | 参数类型                                                                                  | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
|:---|:---|:---|:---|
| name                | 是    | String                                                                                | **参数解释**： 流水线名称。 **约束限制**： 不涉及。 **取值范围**： 仅包含中文、大小写英文字母、数字、'-'和'_'，且长度为\[1,128\]个字符。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                              |
| description         | 否    | String                                                                                | **参数解释**： 流水线描述。 **约束限制**： 不涉及。 **取值范围**： 不超过1024字符。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                              |
| is_publish          | 是    | Boolean                                                                               | **参数解释**： 是否为变更流水线。 **约束限制**： 不涉及。 **取值范围**： - true：变更流水线。   - false：非变更流水线。    **默认取值**： 不涉及。 |
| sources             | 否    | Array of [CodeSource] objects                 | **参数解释**： 流水线源信息。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                   |
| variables           | 否    | Array of [CustomVariable] objects         | **参数解释**： 流水线自定义全局变量列表。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                             |
| schedules           | 否    | Array of [PipelineSchedule] objects     | **参数解释**： 流水线定时执行配置列表。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                              |
| triggers            | 否    | Array of [PipelineTrigger] objects       | **参数解释**： 流水线代码事件触发配置。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                              |
| manifest_version    | 否    | String                                                                                | **参数解释**： 流水线结构定义版本。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 3.0。                                                                                                                                                                                                                                                                                                |
| definition          | 是    | String                                                                                | **参数解释**： 流水线结构定义JSON。该字段结构复杂，建议使用页面编辑流水线后，从[查询流水线详情](https://support.huaweicloud.com/api-pipeline/ShowPipelineDetail.html)接口获取。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                    |
| project_name        | 否    | String                                                                                | **参数解释**： 项目名称。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                     |
| group_id            | 否    | String                                                                                | **参数解释**： 流水线组ID。 **约束限制**： 不涉及。 **取值范围**： 32位字符，仅由数字和字母组成。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                       |
| id                  | 否    | String                                                                                | **参数解释**： 复制场景使用，为流水线组ID。 **约束限制**： 不涉及。 **取值范围**： 32位字符，仅由数字和字母组成。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                               |
| concurrency_control | 否    | [PipelineConcurrencyMgmt] object | **参数解释**： 流水线并发控制信息。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                |
   
 表5CodeSource 
| 参数     | 是否必选 | 参数类型                                                | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
|:---|:---|:---|:---|
| type   | 否    | String                                              | **参数解释**： 流水线源类型。 **约束限制**： 不涉及。 **取值范围**： - code：代码仓。   - artifact：制品仓。    **默认取值**： 不涉及。 |
| params | 否    | [params] object | **参数解释**： 流水线源参数，包含流水线源的详细信息。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                   |
   
 表6params 
| 参数             | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|:---|:---|:---|:---|
| git_type       | 否    | String | **参数解释**： 代码仓类型。 **约束限制**： 不涉及。 **取值范围**： - codehub。   - gitee   - github   - gitcode   - gitlab   - git。    **默认取值**： 不涉及。 |
| codehub_id     | 否    | String | **参数解释**： CodeArts Repo代码仓ID。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| endpoint_id    | 否    | String | **参数解释**： 代码源扩展点ID。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| default_branch | 否    | String | **参数解释**： 默认分支。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| git_url        | 否    | String | **参数解释**： Git仓库https地址，例如https://example.com/CloudPipelinezycs00001/2000.git。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ssh_git_url    | 否    | String | **参数解释**： ssh_git链接地址，例如https://example.com/CloudPipelinezycs00001/2000.git。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| web_url        | 否    | String | **参数解释**： 网页url。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| repo_name      | 否    | String | **参数解释**： 流水线源名称。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| alias          | 否    | String | **参数解释**： 代码仓别名。 **约束限制**： 不涉及。 **取值范围**： 仅支持输入大小写英文字母、数字、"_"，至多128个字符。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
   
 表7CustomVariable 
| 参数           | 是否必选 | 参数类型             | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
|:---|:---|:---|:---|
| pipeline_id  | 否    | String           | **参数解释**： 流水线ID，可以通过[查询流水线列表](https://support.huaweicloud.com/api-pipeline/ListPipelines.html)接口，其中pipelines.pipelineId即为流水线ID。 **约束限制**： 不涉及。 **取值范围**： 32位字符，由数字和字母组成。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                  |
| name         | 否    | String           | **参数解释**： 自定义参数名称。 **约束限制**： 不涉及。 **取值范围**： 仅支持大小写英文字母、数字、"_"，不超过128个字符。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| sequence     | 否    | Integer          | **参数解释**： 参数序号，从1开始。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| type         | 否    | String           | **参数解释**： 自定义参数类型。 **约束限制**： 不涉及。 **取值范围**： - autoIncrement：自增长参数。   - enum：枚举参数。   - string：字符串参数。    **默认取值**： 不涉及。 |
| value        | 否    | String           | **参数解释**： 自定义参数默认值。 **约束限制**： 不涉及。 **取值范围**： 最长8192字符。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| is_secret    | 否    | Boolean          | **参数解释**： 是否私密参数。 **约束限制**： 不涉及。 **取值范围**： - true：是私密参数。   - false：不是私密参数。    **默认取值**： false。                                                                                                                                                         |
| description  | 否    | String           | **参数解释**： 参数描述。 **约束限制**： 不涉及。 **取值范围**： 最长1024字符。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| is_runtime   | 否    | Boolean          | **参数解释**： 是否运行时设置参数。 **约束限制**： 不涉及。 **取值范围**： - true：是运行时设置参数。   - false：不是运行时设置参数。    **默认取值**： false。                                                                                                                                                |
| limits       | 否    | Array of objects | **参数解释**： 枚举值列表。 **约束限制**： 不涉及。 **取值范围**： 每个枚举值不超过1024字符。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| is_reset     | 否    | Boolean          | **参数解释**： 是否重置。自增长参数被编辑，则使用编辑后的值，否则进行末位数字递增。 **约束限制**： 不涉及。 **取值范围**： - true：使用编辑后的参数值。   - false：使用自增长参数。    **默认取值**： false。                                                                                                                         |
| latest_value | 否    | String           | **参数解释**： 最近一次运行的参数值。 **约束限制**： 不涉及。 **取值范围**： 最长8192字符。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
   
 表8PipelineSchedule 
| 参数           | 是否必选 | 参数类型              | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
|:---|:---|:---|:---|
| uuid         | 否    | String            | **参数解释**： 定时任务ID。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| type         | 否    | String            | **参数解释**： 任务类型。 **约束限制**： 不涉及。 **取值范围**： - periodic：周期触发。   - fixed：时间间隔内周期触发。    **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| name         | 否    | String            | **参数解释**： 任务名称。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| enable       | 否    | String            | **参数解释**： 是否启用。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| days_of_week | 否    | Array of integers | **参数解释**： 一周内具体执行日。周日至周六对应1-7。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| time_zone    | 否    | String            | **参数解释**： 时区。 **约束限制**： 不涉及。 **取值范围**： - "China Standard Time"。   - "GMT Standard Time"。   - "South Africa Standard Time"。   - "Russian Standard Time"。   - "SE Asia Standard Time"。   - "Singapore Standard Time"。   - "Pacific SA Standard Time"。   - "E. South America Standard Time"。   - "Central Standard Time (Mexico)"。   - "Egypt Standard Time"。   - "Saudi Arabia Standard Time"。    **默认取值**： 不涉及。 |
   
 表9PipelineTrigger 
| 参数             | 是否必选 | 参数类型                                                                | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
|:---|:---|:---|:---|
| pipeline_id    | 否    | String                                                              | **参数解释**： 流水线ID，可以通过[查询流水线列表](https://support.huaweicloud.com/api-pipeline/ListPipelines.html)接口，其中pipelines.pipelineId即为流水线ID。 **约束限制**： 不涉及。 **取值范围**： 32位字符，由数字和字母组成。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| git_url        | 否    | String                                                              | **参数解释**： 代码仓git链接。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| git_type       | 否    | String                                                              | **参数解释**： git代码仓类型。 **约束限制**： 不涉及。 **取值范围**： - codehub。   - gitee   - github   - gitcode   - gitlab   - git。    **默认取值**： 不涉及。 |
| is_auto_commit | 否    | Boolean                                                             | **参数解释**： 是否自动提交。gitee仓库特有，webhook触发流水线后，自动添加评论。 **约束限制**： 不涉及。 **取值范围**： - true：是自动提交。   - false：不是自动提交。    **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| events         | 否    | Array of [CodeEvent] objects | **参数解释**： 触发事件列表。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| hook_id        | 否    | String                                                              | **参数解释**： 系统生成的回调ID。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| repo_id        | 否    | String                                                              | **参数解释**： Repo仓库ID。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| endpoint_id    | 否    | String                                                              | **参数解释**： 代码源扩展点ID。 **约束限制**： 不涉及。 **取值范围**： 32位字符，由数字和字母组成。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| callback_url   | 否    | String                                                              | **参数解释**： 回调链接，注册Webhook时生成。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| security_token | 否    | String                                                              | **参数解释**： 用户token，注册Webhook时生成。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
   
 表10CodeEvent 
| 参数     | 是否必选 | 参数类型    | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
|:---|:---|:---|:---|
| type   | 否    | String  | **参数解释**： 事件类型。 **约束限制**： 不涉及。 **取值范围**： - merge_request：MR 触发。   - push：代码Push触发。   - tag_push：标签触发。   - issue：Gitee仓库ISSUE触发。   - note：Gitee仓库评论触发。    **默认取值**： 不涉及。 |
| enable | 否    | Boolean | **参数解释**： 代码仓是否可用。 **约束限制**： 不涉及。 **取值范围**： - true：代码仓可用。   - false：代码仓不可用。    **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
   
 表11PipelineConcurrencyMgmt 
| 参数                 | 是否必选 | 参数类型    | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|:---|:---|:---|:---|
| pipeline_id        | 否    | String  | **参数解释**： 流水线ID，可以通过[查询流水线列表](https://support.huaweicloud.com/api-pipeline/ListPipelines.html)接口，其中pipelines.pipelineId即为流水线ID。 **约束限制**： 不涉及。 **取值范围**： 32位字符串。 **默认取值**： 不涉及。                                                                                                                                                                                   |
| concurrency_number | 否    | Integer | **参数解释**： 流水线并发个数。流水线并发个数，最大并发受套餐和购买并发数限制。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                           |
| exceed_action      | 否    | String  | **参数解释**： 超出并发数时排队策略。 **约束限制**： 不涉及。 **取值范围**： - ABORT：忽略不执行。   - QUEUE：排队等待。    **默认取值**： 不涉及。 |
| create_time        | 否    | Long    | **参数解释**： 创建时间。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                      |
| update_time        | 否    | Long    | **参数解释**： 更新时间。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                      |
| enable             | 否    | Boolean | **参数解释**： 是否启用。 **约束限制**： 不涉及。 **取值范围**： - true：启用。   - false：未启用。    **默认取值**： 不涉及。            |
   
#### 响应参数
**状态码：200**
表12响应Body参数 
| 参数          | 参数类型   | 描述                                                                                                                                                                                                                                                                        |
|:---|:---|:---|
| pipeline_id | String | **参数解释**： 流水线ID，可以通过[查询流水线列表](https://support.huaweicloud.com/api-pipeline/ListPipelines.html)接口，其中pipelines.pipelineId即为流水线ID。 **取值范围**： 32位字符，仅由数字和字母组成。 |
   
#### 请求示例
```
POST https://{endpoint}/v5/d80a8a6530324b7bac972cbb8a9f28ec/api/pipelines
{
  "name" : "新建流水线-20231024204112",
  "description" : "",
  "is_publish" : false,
  "sources" : [ {
    "type" : "code",
    "params" : {
      "git_type" : "codehub",
      "codehub_id" : "2111699317",
      "endpoint_id" : "",
      "default_branch" : "master",
      "git_url" : "https://example.com/0213yjw100001/0213yjw1-android.git",
      "ssh_git_url" : "git@example.com:0213yjw100001/0213yjw1-android.git",
      "web_url" : "",
      "repo_name" : "0213yjw1-android",
      "alias" : ""
    }
  } ],
  "definition" : "{\"stages\":[{\"id\":1698151278179,\"identifier\":\"169815127817987dd9f1d-7821-46e4-89be-2a95b01b0533\",\"run_always\":false,\"name\":\"阶段_1\",\"sequence\":\"0\",\"jobs\":[{\"id\":\"\",\"stage_id\":1698151278179,\"identifier\":\"1698151278179f6548479-2eaf-420a-92a4-92d9a711c51b\",\"name\":\"新建任务\",\"depends_on\":[],\"timeout\":\"\",\"timeout_unit\":\"\",\"steps\":[],\"exec_type\":\"AGENTLESS_JOB\",\"sequence\":0}],\"rule_templates\":[],\"pre\":[{\"task\":\"official_devcloud_autoTrigger\",\"sequence\":0}],\"post\":[],\"depends_on\":[]}]}"
}
```
#### 响应示例
**状态码：200**
OK
```
{
  "pipeline_id" : "8bfbd69eac154a0da341705a36294aca"
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  ```
  package com.huaweicloud.sdk.test;
  import com.huaweicloud.sdk.core.auth.ICredential;
  import com.huaweicloud.sdk.core.auth.BasicCredentials;
  import com.huaweicloud.sdk.core.exception.ConnectionException;
  import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
  import com.huaweicloud.sdk.core.exception.ServiceResponseException;
  import com.huaweicloud.sdk.codeartspipeline.v2.region.CodeArtsPipelineRegion;
  import com.huaweicloud.sdk.codeartspipeline.v2.*;
  import com.huaweicloud.sdk.codeartspipeline.v2.model.*;
  import java.util.List;
  import java.util.ArrayList;
  public class CreatePipelineNewSolution {
      public static void main(String[] args) {
          // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
          // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
          String ak = System.getenv("CLOUD_SDK_AK");
          String sk = System.getenv("CLOUD_SDK_SK");
          ICredential auth = new BasicCredentials()
                  .withAk(ak)
                  .withSk(sk);
          CodeArtsPipelineClient client = CodeArtsPipelineClient.newBuilder()
                  .withCredential(auth)
                  .withRegion(CodeArtsPipelineRegion.valueOf("<YOUR REGION>"))
                  .build();
          CreatePipelineNewRequest request = new CreatePipelineNewRequest();
          request.withProjectId("{project_id}");
          PipelineDTO body = new PipelineDTO();
          CodeSourceParams paramsSources = new CodeSourceParams();
          paramsSources.withGitType("codehub")
              .withCodehubId("2111699317")
              .withEndpointId("")
              .withDefaultBranch("master")
              .withGitUrl("https://example.com/0213yjw100001/0213yjw1-android.git")
              .withSshGitUrl("git@example.com:0213yjw100001/0213yjw1-android.git")
              .withWebUrl("")
              .withRepoName("0213yjw1-android")
              .withAlias("");
          List<CodeSource> listbodySources = new ArrayList<>();
          listbodySources.add(
              new CodeSource()
                  .withType("code")
                  .withParams(paramsSources)
          );
          body.withDefinition("{"stages":[{"id":1698151278179,"identifier":"169815127817987dd9f1d-7821-46e4-89be-2a95b01b0533","run_always":false,"name":"阶段_1","sequence":"0","jobs":[{"id":"","stage_id":1698151278179,"identifier":"1698151278179f6548479-2eaf-420a-92a4-92d9a711c51b","name":"新建任务","depends_on":[],"timeout":"","timeout_unit":"","steps":[],"exec_type":"AGENTLESS_JOB","sequence":0}],"rule_templates":[],"pre":[{"task":"official_devcloud_autoTrigger","sequence":0}],"post":[],"depends_on":[]}]}");
          body.withSources(listbodySources);
          body.withIsPublish(false);
          body.withDescription("");
          body.withName("新建流水线-20231024204112");
          request.withBody(body);
          try {
              CreatePipelineNewResponse response = client.createPipelineNew(request);
              System.out.println(response.toString());
          } catch (ConnectionException e) {
              e.printStackTrace();
          } catch (RequestTimeoutException e) {
              e.printStackTrace();
          } catch (ServiceResponseException e) {
              e.printStackTrace();
              System.out.println(e.getHttpStatusCode());
              System.out.println(e.getRequestId());
              System.out.println(e.getErrorCode());
              System.out.println(e.getErrorMsg());
          }
      }
  }
  ```
- [Python]
  ```
  # coding: utf-8
  import os
  from huaweicloudsdkcore.auth.credentials import BasicCredentials
  from huaweicloudsdkcodeartspipeline.v2.region.codeartspipeline_region import CodeArtsPipelineRegion
  from huaweicloudsdkcore.exceptions import exceptions
  from huaweicloudsdkcodeartspipeline.v2 import *
  if __name__ == "__main__":
      # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
      # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
      ak = os.environ["CLOUD_SDK_AK"]
      sk = os.environ["CLOUD_SDK_SK"]
      credentials = BasicCredentials(ak, sk)
      client = CodeArtsPipelineClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(CodeArtsPipelineRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = CreatePipelineNewRequest()
          request.project_id = "{project_id}"
          paramsSources = CodeSourceParams(
              git_type="codehub",
              codehub_id="2111699317",
              endpoint_id="",
              default_branch="master",
              git_url="https://example.com/0213yjw100001/0213yjw1-android.git",
              ssh_git_url="git@example.com:0213yjw100001/0213yjw1-android.git",
              web_url="",
              repo_name="0213yjw1-android",
              alias=""
          )
          listSourcesbody = [
              CodeSource(
                  type="code",
                  params=paramsSources
              )
          ]
          request.body = PipelineDTO(
              definition="{"stages":[{"id":1698151278179,"identifier":"169815127817987dd9f1d-7821-46e4-89be-2a95b01b0533","run_always":false,"name":"阶段_1","sequence":"0","jobs":[{"id":"","stage_id":1698151278179,"identifier":"1698151278179f6548479-2eaf-420a-92a4-92d9a711c51b","name":"新建任务","depends_on":[],"timeout":"","timeout_unit":"","steps":[],"exec_type":"AGENTLESS_JOB","sequence":0}],"rule_templates":[],"pre":[{"task":"official_devcloud_autoTrigger","sequence":0}],"post":[],"depends_on":[]}]}",
              sources=listSourcesbody,
              is_publish=False,
              description="",
              name="新建流水线-20231024204112"
          )
          response = client.create_pipeline_new(request)
          print(response)
      except exceptions.ClientRequestException as e:
          print(e.status_code)
          print(e.request_id)
          print(e.error_code)
          print(e.error_msg)
  ```
- [Go]
  ```
  package main
  import (
  "fmt"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
      codeartspipeline "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartspipeline/v2"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartspipeline/v2/model"
      region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartspipeline/v2/region"
  )
  func main() {
      // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
      // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
      ak := os.Getenv("CLOUD_SDK_AK")
      sk := os.Getenv("CLOUD_SDK_SK")
      auth, err := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      hcClient, err := codeartspipeline.CodeArtsPipelineClientBuilder().
           WithRegion(region.ValueOf("<YOUR REGION>")).
           WithCredential(auth).
           SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      client := codeartspipeline.NewCodeArtsPipelineClient(hcClient)
      request := &model.CreatePipelineNewRequest{}
  request.ProjectId = "{project_id}"
  gitTypeParams:= "codehub"
  codehubIdParams:= "2111699317"
  endpointIdParams:= ""
  defaultBranchParams:= "master"
  gitUrlParams:= "https://example.com/0213yjw100001/0213yjw1-android.git"
  sshGitUrlParams:= "git@example.com:0213yjw100001/0213yjw1-android.git"
  webUrlParams:= ""
  repoNameParams:= "0213yjw1-android"
  aliasParams:= ""
  paramsSources := &model.CodeSourceParams{
  GitType: &gitTypeParams,
  CodehubId: &codehubIdParams,
  EndpointId: &endpointIdParams,
  DefaultBranch: &defaultBranchParams,
  GitUrl: &gitUrlParams,
  SshGitUrl: &sshGitUrlParams,
  WebUrl: &webUrlParams,
  RepoName: &repoNameParams,
  Alias: &aliasParams,
  }
  typeSources:= "code"
  var listSourcesbody = []model.CodeSource{
          {
              Type: &typeSources,
              Params: paramsSources,
          },
      }
  descriptionPipelineDto:= ""
  request.Body = &model.PipelineDto{
  Definition: "{"stages":[{"id":1698151278179,"identifier":"169815127817987dd9f1d-7821-46e4-89be-2a95b01b0533","run_always":false,"name":"阶段_1","sequence":"0","jobs":[{"id":"","stage_id":1698151278179,"identifier":"1698151278179f6548479-2eaf-420a-92a4-92d9a711c51b","name":"新建任务","depends_on":[],"timeout":"","timeout_unit":"","steps":[],"exec_type":"AGENTLESS_JOB","sequence":0}],"rule_templates":[],"pre":[{"task":"official_devcloud_autoTrigger","sequence":0}],"post":[],"depends_on":[]}]}",
  Sources: &listSourcesbody,
  IsPublish: false,
  Description: &descriptionPipelineDto,
  Name: "新建流水线-20231024204112",
  }
  response, err := client.CreatePipelineNew(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/CodeArtsPipeline/sdk?api=CreatePipelineNew)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述           |
|:---|:---|
| 200 | OK           |
| 401 | Unauthorized |
| 403 | Forbidden    |
| 404 | Not Found    |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-pipeline/ErrorCode.html)。
