更新时间:2025-07-31 GMT+08:00
分享

新建应用 (推荐)

功能介绍

新建应用。

调用方法

请参见如何调用API

URI

POST /v1/applications

请求参数

表1 请求Header参数

参数

是否必选

参数类型

描述

Content-Type

String

参数解释

消息体的类型(格式)。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

X-Auth-Token

String

参数解释

用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

约束限制

不涉及。

取值范围

字符串,长度不超过20000个字符。

默认取值

不涉及。

表2 请求Body参数

参数

是否必选

参数类型

描述

project_id

String

参数解释

项目id,获取方式请参见获取项目id

约束限制

不涉及。

取值范围

只能由英文字母、数字组成,且长度为32个字符。

默认取值

不涉及。

name

String

参数解释

应用名称。

约束限制

不涉及。

取值范围

由中文字符、英文字母、数字及“_”、“-”组成,且长度为[3-128]个字符。

默认取值

不涉及。

description

String

参数解释

应用描述信息。

约束限制

不涉及。

取值范围

最大长度为1024个字符。

默认取值

不涉及。

group_id

String

参数解释

应用的分组id,传入no_grouped为未分组的应用。

约束限制

不涉及。

取值范围

只能由英文字母、数字组成,且长度为32个字符 或者 no_grouped。

默认取值

不涉及。

is_draft

Boolean

参数解释

是否为草稿。

约束限制

不涉及。

取值范围

  • true: 草稿应用。

  • false: 非草稿应用。

默认取值

不涉及。

create_type

String

参数解释

创建类型。

约束限制

不涉及。

取值范围

  • template: 模板创建。

默认取值

不涉及。

slave_cluster_id

String

参数解释

slave集群id,默认为空,为空时使用默认资源池。

约束限制

不涉及。

取值范围

只能由英文字母、数字组成,且长度为[1-32]个字符。

默认取值

不涉及。

trigger

TaskTriggerVO object

参数解释

部署任务触发场景配置。

约束限制

填写trigger时,trigger_source必填。

arrange_infos

Array of TaskV2RequestBody objects

参数解释

部署任务列表信息。

约束限制

不涉及。

表3 TaskTriggerVO

参数

是否必选

参数类型

描述

trigger_source

String

参数解释

部署任务允许执行的场景。

约束限制

不涉及。

取值范围

  • 0: 所有执行请求均可执行。

  • 1: 只允许流水线触发执行。

默认取值

不涉及。

artifact_source_system

String

参数解释

当任务只允许流水线触发执行时,流水线传递的来源信息。

约束限制

不涉及。

取值范围

  • Artifact: 来源信息为CodeArtsArtifact。

默认取值

不涉及。

artifact_type

String

参数解释

当任务只允许流水线触发执行时,对应流水线源的制品仓库类型。

约束限制

不涉及。

取值范围

  • generic: 软件发布库。

  • docker: Docker库。

默认取值

不涉及。

表4 TaskV2RequestBody

参数

是否必选

参数类型

描述

template_id

String

参数解释

部署模板id。

约束限制

不涉及。

取值范围

只能由英文字母、数字组成,且长度为32个字符。

默认取值

不涉及。

operation_list

Array of DeployV2OperationsDO objects

参数解释

部署编排列表信息。

约束限制

不涉及。

表5 DeployV2OperationsDO

参数

是否必选

参数类型

描述

id

String

参数解释

步骤id。

约束限制

不涉及。

取值范围

只能由数字组成。

默认取值

不涉及。

name

String

参数解释

步骤名称。

约束限制

不涉及。

取值范围

长度为1~128个字符。

默认取值

不涉及。

description

String

参数解释

步骤描述。

约束限制

不涉及。

取值范围

长度最长为1024个字符。

默认取值

不涉及。

code

String

参数解释

步骤下载地址。

约束限制

不涉及。

取值范围

长度最长为102400个字符。

默认取值

不涉及。

params

String

参数解释

步骤详细定义。

约束限制

不涉及。

取值范围

长度最长为204800个字符。

默认取值

不涉及。

entrance

String

参数解释

步骤入口函数。

约束限制

不涉及。

取值范围

长度最长为1024个字符。

默认取值

不涉及。

version

String

参数解释

步骤版本。

约束限制

不涉及。

取值范围

长度最长为1024个字符。

默认取值

不涉及。

module_id

String

参数解释

步骤模块id。

约束限制

不涉及。

取值范围

长度最长为1024个字符。

默认取值

不涉及。

响应参数

状态码:200

表6 响应Body参数

参数

参数类型

描述

status

String

参数解释

请求成功失败状态。

取值范围

  • success: 成功。

  • error: 失败。

result

AppBaseResponse object

参数解释

应用基本信息响应体。

表7 AppBaseResponse

参数

参数类型

描述

id

String

参数解释

应用id。

取值范围

由英文字母、数字组成,且长度为32个字符。

name

String

参数解释

应用名称。

取值范围

由中文字符、英文字母、数字及“_”、“-”组成,且长度为[3-128]个字符。

region

String

参数解释

应用所属区域。

取值范围

不涉及。

arrange_infos

Array of TaskBaseBody objects

参数解释

部署任务列表。

表8 TaskBaseBody

参数

参数类型

描述

id

String

参数解释

部署任务id。

取值范围

由英文字母、数字组成,且长度为32个字符。

请求示例

创建一个应用

https://{endpoint}/v1/applications

{
  "name" : "testApp",
  "project_id" : "55837d272adf4eee90319800e2da6961",
  "description" : "使用模板创建应用",
  "trigger" : {
    "trigger_source" : 0,
    "artifact_source_system" : "",
    "artifact_type" : ""
  },
  "slave_cluster_id" : "",
  "create_type" : "template",
  "is_draft" : true,
  "arrange_infos" : [ {
    "template_id" : "43b36b4678f743568e1ffebfd7f4ce76",
    "operation_list" : [ {
      "name" : "Kubernetes Manifest部署(CCE集群)",
      "description" : "通过manifest文件定义Kubernetes对象,实现对华为云CCE集群的部署。[查看操作指南](https://support.huaweicloud.com/usermanual-deployman/deployman_hlp_1096.html)",
      "code" : "https://example.com",
      "params" : "[{\"name\":\"datasource\",\"label\":\"Manifest文件来源\",\"displaySettings\":{\"DevCloud.ControlType\":\"Radio\",\"DevCloud.ControlType.Style\":\"ButtonGroup\",\"DevCloud.ControlType.Radio\":[{\"displayName\":\"制品仓库\",\"value\":\"1\"},{\"displayName\":\"代码仓库\",\"value\":\"2\"},{\"displayName\":\"obs\",\"value\":\"4\"}],\"DevCloud.ControlType.Default\":{\"displayName\":\"制品仓库\",\"value\":\"1\",\"icon\":\"img/release.png\"}},\"defaultDisplay\":[{\"displayName\":\"制品仓库\",\"value\":\"1\"}],\"validation\":{\"pattern\":null,\"patternDescription\":null,\"maxLength\":null,\"dataType\":null,\"isRequired\":true,\"isNotParameter\":true}},{\"name\":\"deployTenant\",\"label\":\"部署租户\",\"displaySettings\":{\"DevCloud.ControlType\":\"Select\",\"DevCloud.ControlType.Style\":null,\"DevCloud.ControlType.Select\":[{\"displayName\":\"当前租户\",\"value\":\"local\"},{\"displayName\":\"其他租户\",\"value\":\"other\"}],\"DevCloud.ControlType.Default\":{\"displayName\":\"当前租户\",\"value\":\"local\"}},\"defaultDisplay\":[{\"displayName\":\"当前租户\",\"value\":\"local\"}],\"validation\":{\"pattern\":null,\"patternDescription\":null,\"maxLength\":null,\"dataType\":null,\"isRequired\":true,\"isNotParameter\":true}},{\"name\":\"use_iam_checkbox\",\"displaySettings\":{\"DevCloud.ControlType\":\"Checkbox\",\"DevCloud.ControlType.Style\":null,\"DevCloud.ControlType.Checkbox\":[{\"displayName\":\"IAM授权\",\"value\":\"0\"}]},\"defaultDisplay\":[{\"displayName\":\"IAM授权\",\"value\":\"0\"}],\"visibleRule\":\"deployTenant=local\",\"validation\":{\"pattern\":null,\"patternDescription\":null,\"maxLength\":null,\"dataType\":null,\"isRequired\":false,\"isNotParameter\":true}},{\"name\":\"javaProbeCheckBox\",\"displaySettings\":{\"DevCloud.ControlType\":\"Checkbox\",\"DevCloud.ControlType.Style\":null,\"DevCloud.ControlType.Checkbox\":[{\"displayName\":\"配置JAVA探针\",\"value\":\"0\"}]},\"defaultDisplay\":[{\"displayName\":\"配置JAVA探针\",\"value\":\"0\"}],\"visibleRule\":\"not 1=1\",\"validation\":{\"pattern\":null,\"patternDescription\":null,\"maxLength\":null,\"dataType\":null,\"isRequired\":false,\"isNotParameter\":false}},{\"name\":\"controller_enabled_ignore_errors\",\"displaySettings\":{\"DevCloud.ControlType\":\"Checkbox\",\"DevCloud.ControlType.Style\":null,\"DevCloud.ControlType.Checkbox\":[{\"displayName\":\"失败后继续运行\",\"value\":\"0\"}]},\"defaultDisplay\":[{\"displayName\":\"失败后继续运行\",\"value\":\"0\"}],\"validation\":{\"pattern\":null,\"patternDescription\":null,\"maxLength\":null,\"dataType\":null,\"isRequired\":true,\"isNotParameter\":false}},{\"name\":\"controller_enabled_overtime\",\"label\":\"超时时间\",\"displaySettings\":{\"DevCloud.ControlType\":\"SingleLineText\",\"DevCloud.ControlType.Style\":null},\"defaultValue\":\"10\",\"validation\":{\"pattern\":\"^([1-9]|[1-2][0-9]|30)$\",\"patternDescription\":\"时间单位为分钟,请输入1-30(包含)的整数\",\"maxLength\":null,\"dataType\":null,\"isRequired\":true,\"isNotParameter\":false}},{\"name\":\"controller_enabled\",\"displaySettings\":{\"DevCloud.ControlType\":\"Hidden\",\"DevCloud.ControlType.Style\":null},\"defaultDisplay\":[{\"displayName\":\"启用\",\"value\":\"1\"}]},{\"name\":\"visibleRule\",\"displaySettings\":{\"DevCloud.ControlType\":\"Hidden\",\"DevCloud.ControlType.Style\":null},\"defaultValue\":\"{\\\"use_iam_checkbox\\\":{\\\"value\\\":true,\\\"condition\\\":\\\"deployTenant=local\\\"},\\\"controller_enabled_overtime\\\":{\\\"value\\\":true},\\\"javaProbeCheckBox\\\":{\\\"value\\\":true,\\\"condition\\\":\\\"not 1=1\\\"},\\\"datasource\\\":{\\\"value\\\":true},\\\"deployTenant\\\":{\\\"value\\\":true},\\\"controller_enabled_ignore_errors\\\":{\\\"value\\\":true}}\"}]",
      "entrance" : "main.yml",
      "version" : "2.3.69",
      "module_id" : "devcloud2018.k8s-cce-manifest-deployment.k8sdeploy-manifest"
    } ]
  } ]
}

响应示例

状态码:200

OK 请求响应成功

{
  "result" : {
    "id" : "e700f15965694253940502911220d76b",
    "name" : "testApp",
    "region" : "region-a",
    "is_disable" : false,
    "arrange_infos" : [ {
      "id" : "3ea35372b6db4d58b187e9a7ee9dc349"
    } ]
  },
  "status" : "success"
}

SDK代码示例

SDK代码示例如下。

Java

创建一个应用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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.codeartsdeploy.v2.region.CodeArtsDeployRegion;
import com.huaweicloud.sdk.codeartsdeploy.v2.*;
import com.huaweicloud.sdk.codeartsdeploy.v2.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreateAppSolution {

    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);

        CodeArtsDeployClient client = CodeArtsDeployClient.newBuilder()
                .withCredential(auth)
                .withRegion(CodeArtsDeployRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateAppRequest request = new CreateAppRequest();
        CreateAppRequestBody body = new CreateAppRequestBody();
        List<DeployV2OperationsDO> listArrangeInfosOperationList = new ArrayList<>();
        listArrangeInfosOperationList.add(
            new DeployV2OperationsDO()
                .withName("Kubernetes Manifest部署(CCE集群)")
                .withDescription("通过manifest文件定义Kubernetes对象,实现对华为云CCE集群的部署。[查看操作指南](https://support.huaweicloud.com/usermanual-deployman/deployman_hlp_1096.html)")
                .withCode("https://example.com")
                .withParams("[{"name":"datasource","label":"Manifest文件来源","displaySettings":{"DevCloud.ControlType":"Radio","DevCloud.ControlType.Style":"ButtonGroup","DevCloud.ControlType.Radio":[{"displayName":"制品仓库","value":"1"},{"displayName":"代码仓库","value":"2"},{"displayName":"obs","value":"4"}],"DevCloud.ControlType.Default":{"displayName":"制品仓库","value":"1","icon":"img/release.png"}},"defaultDisplay":[{"displayName":"制品仓库","value":"1"}],"validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":true}},{"name":"deployTenant","label":"部署租户","displaySettings":{"DevCloud.ControlType":"Select","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Select":[{"displayName":"当前租户","value":"local"},{"displayName":"其他租户","value":"other"}],"DevCloud.ControlType.Default":{"displayName":"当前租户","value":"local"}},"defaultDisplay":[{"displayName":"当前租户","value":"local"}],"validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":true}},{"name":"use_iam_checkbox","displaySettings":{"DevCloud.ControlType":"Checkbox","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Checkbox":[{"displayName":"IAM授权","value":"0"}]},"defaultDisplay":[{"displayName":"IAM授权","value":"0"}],"visibleRule":"deployTenant=local","validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":false,"isNotParameter":true}},{"name":"javaProbeCheckBox","displaySettings":{"DevCloud.ControlType":"Checkbox","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Checkbox":[{"displayName":"配置JAVA探针","value":"0"}]},"defaultDisplay":[{"displayName":"配置JAVA探针","value":"0"}],"visibleRule":"not 1=1","validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":false,"isNotParameter":false}},{"name":"controller_enabled_ignore_errors","displaySettings":{"DevCloud.ControlType":"Checkbox","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Checkbox":[{"displayName":"失败后继续运行","value":"0"}]},"defaultDisplay":[{"displayName":"失败后继续运行","value":"0"}],"validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":false}},{"name":"controller_enabled_overtime","label":"超时时间","displaySettings":{"DevCloud.ControlType":"SingleLineText","DevCloud.ControlType.Style":null},"defaultValue":"10","validation":{"pattern":"^([1-9]|[1-2][0-9]|30)$","patternDescription":"时间单位为分钟,请输入1-30(包含)的整数","maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":false}},{"name":"controller_enabled","displaySettings":{"DevCloud.ControlType":"Hidden","DevCloud.ControlType.Style":null},"defaultDisplay":[{"displayName":"启用","value":"1"}]},{"name":"visibleRule","displaySettings":{"DevCloud.ControlType":"Hidden","DevCloud.ControlType.Style":null},"defaultValue":"{\"use_iam_checkbox\":{\"value\":true,\"condition\":\"deployTenant=local\"},\"controller_enabled_overtime\":{\"value\":true},\"javaProbeCheckBox\":{\"value\":true,\"condition\":\"not 1=1\"},\"datasource\":{\"value\":true},\"deployTenant\":{\"value\":true},\"controller_enabled_ignore_errors\":{\"value\":true}}"}]")
                .withEntrance("main.yml")
                .withVersion("2.3.69")
                .withModuleId("devcloud2018.k8s-cce-manifest-deployment.k8sdeploy-manifest")
        );
        List<TaskV2RequestBody> listbodyArrangeInfos = new ArrayList<>();
        listbodyArrangeInfos.add(
            new TaskV2RequestBody()
                .withTemplateId("43b36b4678f743568e1ffebfd7f4ce76")
                .withOperationList(listArrangeInfosOperationList)
        );
        TaskTriggerVO triggerbody = new TaskTriggerVO();
        triggerbody.withTriggerSource("0")
            .withArtifactSourceSystem("")
            .withArtifactType("");
        body.withArrangeInfos(listbodyArrangeInfos);
        body.withTrigger(triggerbody);
        body.withSlaveClusterId("");
        body.withCreateType(CreateAppRequestBody.CreateTypeEnum.fromValue("template"));
        body.withIsDraft(true);
        body.withDescription("使用模板创建应用");
        body.withName("testApp");
        body.withProjectId("55837d272adf4eee90319800e2da6961");
        request.withBody(body);
        try {
            CreateAppResponse response = client.createApp(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

创建一个应用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcodeartsdeploy.v2.region.codeartsdeploy_region import CodeArtsDeployRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcodeartsdeploy.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 = CodeArtsDeployClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CodeArtsDeployRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateAppRequest()
        listOperationListArrangeInfos = [
            DeployV2OperationsDO(
                name="Kubernetes Manifest部署(CCE集群)",
                description="通过manifest文件定义Kubernetes对象,实现对华为云CCE集群的部署。[查看操作指南](https://support.huaweicloud.com/usermanual-deployman/deployman_hlp_1096.html)",
                code="https://example.com",
                params="[{"name":"datasource","label":"Manifest文件来源","displaySettings":{"DevCloud.ControlType":"Radio","DevCloud.ControlType.Style":"ButtonGroup","DevCloud.ControlType.Radio":[{"displayName":"制品仓库","value":"1"},{"displayName":"代码仓库","value":"2"},{"displayName":"obs","value":"4"}],"DevCloud.ControlType.Default":{"displayName":"制品仓库","value":"1","icon":"img/release.png"}},"defaultDisplay":[{"displayName":"制品仓库","value":"1"}],"validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":true}},{"name":"deployTenant","label":"部署租户","displaySettings":{"DevCloud.ControlType":"Select","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Select":[{"displayName":"当前租户","value":"local"},{"displayName":"其他租户","value":"other"}],"DevCloud.ControlType.Default":{"displayName":"当前租户","value":"local"}},"defaultDisplay":[{"displayName":"当前租户","value":"local"}],"validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":true}},{"name":"use_iam_checkbox","displaySettings":{"DevCloud.ControlType":"Checkbox","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Checkbox":[{"displayName":"IAM授权","value":"0"}]},"defaultDisplay":[{"displayName":"IAM授权","value":"0"}],"visibleRule":"deployTenant=local","validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":false,"isNotParameter":true}},{"name":"javaProbeCheckBox","displaySettings":{"DevCloud.ControlType":"Checkbox","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Checkbox":[{"displayName":"配置JAVA探针","value":"0"}]},"defaultDisplay":[{"displayName":"配置JAVA探针","value":"0"}],"visibleRule":"not 1=1","validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":false,"isNotParameter":false}},{"name":"controller_enabled_ignore_errors","displaySettings":{"DevCloud.ControlType":"Checkbox","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Checkbox":[{"displayName":"失败后继续运行","value":"0"}]},"defaultDisplay":[{"displayName":"失败后继续运行","value":"0"}],"validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":false}},{"name":"controller_enabled_overtime","label":"超时时间","displaySettings":{"DevCloud.ControlType":"SingleLineText","DevCloud.ControlType.Style":null},"defaultValue":"10","validation":{"pattern":"^([1-9]|[1-2][0-9]|30)$","patternDescription":"时间单位为分钟,请输入1-30(包含)的整数","maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":false}},{"name":"controller_enabled","displaySettings":{"DevCloud.ControlType":"Hidden","DevCloud.ControlType.Style":null},"defaultDisplay":[{"displayName":"启用","value":"1"}]},{"name":"visibleRule","displaySettings":{"DevCloud.ControlType":"Hidden","DevCloud.ControlType.Style":null},"defaultValue":"{\"use_iam_checkbox\":{\"value\":true,\"condition\":\"deployTenant=local\"},\"controller_enabled_overtime\":{\"value\":true},\"javaProbeCheckBox\":{\"value\":true,\"condition\":\"not 1=1\"},\"datasource\":{\"value\":true},\"deployTenant\":{\"value\":true},\"controller_enabled_ignore_errors\":{\"value\":true}}"}]",
                entrance="main.yml",
                version="2.3.69",
                module_id="devcloud2018.k8s-cce-manifest-deployment.k8sdeploy-manifest"
            )
        ]
        listArrangeInfosbody = [
            TaskV2RequestBody(
                template_id="43b36b4678f743568e1ffebfd7f4ce76",
                operation_list=listOperationListArrangeInfos
            )
        ]
        triggerbody = TaskTriggerVO(
            trigger_source="0",
            artifact_source_system="",
            artifact_type=""
        )
        request.body = CreateAppRequestBody(
            arrange_infos=listArrangeInfosbody,
            trigger=triggerbody,
            slave_cluster_id="",
            create_type="template",
            is_draft=True,
            description="使用模板创建应用",
            name="testApp",
            project_id="55837d272adf4eee90319800e2da6961"
        )
        response = client.create_app(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

创建一个应用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    codeartsdeploy "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartsdeploy/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartsdeploy/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartsdeploy/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 := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := codeartsdeploy.NewCodeArtsDeployClient(
        codeartsdeploy.CodeArtsDeployClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateAppRequest{}
	nameOperationList:= "Kubernetes Manifest部署(CCE集群)"
	descriptionOperationList:= "通过manifest文件定义Kubernetes对象,实现对华为云CCE集群的部署。[查看操作指南](https://support.huaweicloud.com/usermanual-deployman/deployman_hlp_1096.html)"
	codeOperationList:= "https://example.com"
	paramsOperationList:= "[{"name":"datasource","label":"Manifest文件来源","displaySettings":{"DevCloud.ControlType":"Radio","DevCloud.ControlType.Style":"ButtonGroup","DevCloud.ControlType.Radio":[{"displayName":"制品仓库","value":"1"},{"displayName":"代码仓库","value":"2"},{"displayName":"obs","value":"4"}],"DevCloud.ControlType.Default":{"displayName":"制品仓库","value":"1","icon":"img/release.png"}},"defaultDisplay":[{"displayName":"制品仓库","value":"1"}],"validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":true}},{"name":"deployTenant","label":"部署租户","displaySettings":{"DevCloud.ControlType":"Select","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Select":[{"displayName":"当前租户","value":"local"},{"displayName":"其他租户","value":"other"}],"DevCloud.ControlType.Default":{"displayName":"当前租户","value":"local"}},"defaultDisplay":[{"displayName":"当前租户","value":"local"}],"validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":true}},{"name":"use_iam_checkbox","displaySettings":{"DevCloud.ControlType":"Checkbox","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Checkbox":[{"displayName":"IAM授权","value":"0"}]},"defaultDisplay":[{"displayName":"IAM授权","value":"0"}],"visibleRule":"deployTenant=local","validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":false,"isNotParameter":true}},{"name":"javaProbeCheckBox","displaySettings":{"DevCloud.ControlType":"Checkbox","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Checkbox":[{"displayName":"配置JAVA探针","value":"0"}]},"defaultDisplay":[{"displayName":"配置JAVA探针","value":"0"}],"visibleRule":"not 1=1","validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":false,"isNotParameter":false}},{"name":"controller_enabled_ignore_errors","displaySettings":{"DevCloud.ControlType":"Checkbox","DevCloud.ControlType.Style":null,"DevCloud.ControlType.Checkbox":[{"displayName":"失败后继续运行","value":"0"}]},"defaultDisplay":[{"displayName":"失败后继续运行","value":"0"}],"validation":{"pattern":null,"patternDescription":null,"maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":false}},{"name":"controller_enabled_overtime","label":"超时时间","displaySettings":{"DevCloud.ControlType":"SingleLineText","DevCloud.ControlType.Style":null},"defaultValue":"10","validation":{"pattern":"^([1-9]|[1-2][0-9]|30)$","patternDescription":"时间单位为分钟,请输入1-30(包含)的整数","maxLength":null,"dataType":null,"isRequired":true,"isNotParameter":false}},{"name":"controller_enabled","displaySettings":{"DevCloud.ControlType":"Hidden","DevCloud.ControlType.Style":null},"defaultDisplay":[{"displayName":"启用","value":"1"}]},{"name":"visibleRule","displaySettings":{"DevCloud.ControlType":"Hidden","DevCloud.ControlType.Style":null},"defaultValue":"{\"use_iam_checkbox\":{\"value\":true,\"condition\":\"deployTenant=local\"},\"controller_enabled_overtime\":{\"value\":true},\"javaProbeCheckBox\":{\"value\":true,\"condition\":\"not 1=1\"},\"datasource\":{\"value\":true},\"deployTenant\":{\"value\":true},\"controller_enabled_ignore_errors\":{\"value\":true}}"}]"
	entranceOperationList:= "main.yml"
	versionOperationList:= "2.3.69"
	moduleIdOperationList:= "devcloud2018.k8s-cce-manifest-deployment.k8sdeploy-manifest"
	var listOperationListArrangeInfos = []model.DeployV2OperationsDo{
        {
            Name: &nameOperationList,
            Description: &descriptionOperationList,
            Code: &codeOperationList,
            Params: &paramsOperationList,
            Entrance: &entranceOperationList,
            Version: &versionOperationList,
            ModuleId: &moduleIdOperationList,
        },
    }
	templateIdArrangeInfos:= "43b36b4678f743568e1ffebfd7f4ce76"
	var listArrangeInfosbody = []model.TaskV2RequestBody{
        {
            TemplateId: &templateIdArrangeInfos,
            OperationList: &listOperationListArrangeInfos,
        },
    }
	triggerSourceTrigger:= "0"
	artifactSourceSystemTrigger:= ""
	artifactTypeTrigger:= ""
	triggerbody := &model.TaskTriggerVo{
		TriggerSource: &triggerSourceTrigger,
		ArtifactSourceSystem: &artifactSourceSystemTrigger,
		ArtifactType: &artifactTypeTrigger,
	}
	slaveClusterIdCreateAppRequestBody:= ""
	descriptionCreateAppRequestBody:= "使用模板创建应用"
	request.Body = &model.CreateAppRequestBody{
		ArrangeInfos: &listArrangeInfosbody,
		Trigger: triggerbody,
		SlaveClusterId: &slaveClusterIdCreateAppRequestBody,
		CreateType: model.GetCreateAppRequestBodyCreateTypeEnum().TEMPLATE,
		IsDraft: true,
		Description: &descriptionCreateAppRequestBody,
		Name: "testApp",
		ProjectId: "55837d272adf4eee90319800e2da6961",
	}
	response, err := client.CreateApp(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK 请求响应成功

错误码

请参见错误码

相关文档