更新时间:2024-05-06 GMT+08:00
分享

查询模板列表

功能介绍

查询模板列表,支持分页查询,支持模板名字模糊查询

调用方法

请参见如何调用API

URI

GET /v3/templates

表1 Query参数

参数

是否必选

参数类型

描述

template_type

String

模板类型

is_build_in

String

是否内置模板

offset

Integer

偏移量,表示从此偏移量开始查询,offset大于等于0

limit

Integer

每页显示的条目数量

name

String

模板名称,匹配规则为模糊匹配

sort

String

排序字段

asc

String

是否正序

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

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

响应参数

状态码: 200

表3 响应Body参数

参数

参数类型

描述

total

Integer

总数

page_number

Integer

页码数

page_size

Integer

每页显示数

content

Array of TemplateView objects

模板数据,list类型数据

表4 TemplateView

参数

参数类型

描述

template_id

String

模板ID

template_name

String

模板名字

template_type

String

模板类型

template_url

String

模板编辑URL

user_id

String

用户ID

user_name

String

用户名字

domain_id

String

租户ID

domain_name

String

租户名字

is_build_in

Boolean

是否内置模板

region

String

系统模板region为Cloud Pipeline。自定义模板region为实际region

project_id

String

项目ID

project_name

String

项目名字

create_time

String

创建时间

last_modify_time

String

修改时间

is_watch

Boolean

是否关注

description

String

模板描述

parameter

Array of TemplateParam objects

模板参数

flow

Map<String,Map<String,String>>

编排flow详情,描述流水线内各阶段任务的串并行关系。map类型数据,key为阶段名字,默认第一阶段initial,最后阶段为final,其余名字以'state_数字'标识。value为该阶段内任务(以'Task_数字'标识)以及后续阶段的标识。本字段为描述流水线基础编排数据之一,建议可通过流水线真实界面基于模板创建接口中获取

states

Map<String,TemplateState>

编排State详情,map类型数据。本字段为描述流水线基础编排数据之一,建议可通过流水线真实界面基于模板创建接口中获取

can_update

Boolean

是否可以修改

can_delete

Boolean

是否可以删除

need_hub

Boolean

是否需要代码仓库

表5 TemplateParam

参数

参数类型

描述

required

String

是否必须

visible

String

是否可见

name

String

流水线参数名字

value

String

流水线参数值

description

String

流水线参数描述

paramtype

String

流水线参数类型

display_type

String

流水线参数展示类型

display_name

String

流水线参数展示名字

is_static

Boolean

是否静态参数

is_default

Boolean

是否默认参数

limits

Array of ParamTypeLimits objects

array类型数据

constraints

Array of Constraint objects

array类型数据

表6 ParamTypeLimits

参数

参数类型

描述

disable

String

是否废弃

name

String

语言名字

displayname

String

语言展示名字

id

String

策略ID

language

String

扫描语言

表7 Constraint

参数

参数类型

描述

type

String

校验规则类型

value

String

校验规则

errormsg

String

校验失败描述

表8 TemplateState

参数

参数类型

描述

type

String

任务类型

name

String

任务名字

module_or_template_id

String

模板任务ID

module_or_template_name

String

模板任务名字

display_name

String

任务在流水线页面展示名字

dsl_method

String

流水线可挂载任务类型

parameters

Map<String,Object>

任务参数,map类型数据

is_manual_execution

Boolean

是否手动执行

job_parameter_validate

Boolean

任务参数是否校验

is_show_codehub_url

Boolean

是否显示代码仓URL

is_execute

Boolean

是否执行

job_id

String

执行任务ID

job_name

String

执行任务名字

project_id

String

任务所属项目ID

execution_mode

String

控制阶段下任务的串并行(type是task的execution_mode值为null,type是stage的execution_mode可选parallel(并行)或者serial(串行))

状态码: 400

表9 响应Body参数

参数

参数类型

描述

error_msg

String

错误信息

error_code

String

错误码

请求示例

GET https://{endpoint}/v3/templates?template_type=pipeline&is_build_in=false&offset=0&limit=10

响应示例

SDK代码示例

SDK代码示例如下。

 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
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.*;


public class ListTemplatesSolution {

    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();
        ListTemplatesRequest request = new ListTemplatesRequest();
        request.withTemplateType("<template_type>");
        request.withIsBuildIn("<is_build_in>");
        request.withOffset(<offset>);
        request.withLimit(<limit>);
        request.withName("<name>");
        request.withSort("<sort>");
        request.withAsc("<asc>");
        try {
            ListTemplatesResponse response = client.listTemplates(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());
        }
    }
}
 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
# coding: utf-8

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 = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = CodeArtsPipelineClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CodeArtsPipelineRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListTemplatesRequest()
        request.template_type = "<template_type>"
        request.is_build_in = "<is_build_in>"
        request.offset = <offset>
        request.limit = <limit>
        request.name = "<name>"
        request.sort = "<sort>"
        request.asc = "<asc>"
        response = client.list_templates(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 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
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 := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := codeartspipeline.NewCodeArtsPipelineClient(
        codeartspipeline.CodeArtsPipelineClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListTemplatesRequest{}
	request.TemplateType = "<template_type>"
	request.IsBuildIn = "<is_build_in>"
	offsetRequest:= int32(<offset>)
	request.Offset = &offsetRequest
	limitRequest:= int32(<limit>)
	request.Limit = &limitRequest
	nameRequest:= "<name>"
	request.Name = &nameRequest
	sortRequest:= "<sort>"
	request.Sort = &sortRequest
	ascRequest:= "<asc>"
	request.Asc = &ascRequest
	response, err := client.ListTemplates(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

OK

400

Bad request

401

Unauthorized

403

Forbidden

404

Not Found

错误码

请参见错误码

分享:

    相关文档

    相关产品