Updated on 2024-06-14 GMT+08:00

Querying Template List

Function

This API is used to query the template list. Pagination query is supported. Fuzzy query by template name is supported.

Calling Method

For details, see Calling APIs.

URI

GET /v3/templates

Table 1 Query Parameters

Parameter

Mandatory

Type

Description

template_type

Yes

String

Template type.

is_build_in

Yes

String

Whether the template is a built-in template or not.

offset

No

Integer

Offset, which is the position where the query starts. The value must be no less than 0.

limit

No

Integer

Number of records displayed on each page.

name

No

String

Template name, which is fuzzily matched.

sort

No

String

Sorting field.

asc

No

String

Whether the sequence is in ascending order.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

No

String

User token. It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

total

Integer

Total number.

page_number

Integer

Page number.

page_size

Integer

Number of records displayed on each page.

content

Array of TemplateView objects

Template data, which is a value of list type.

Table 4 TemplateView

Parameter

Type

Description

template_id

String

Template ID.

template_name

String

Template name.

template_type

String

Template type.

template_url

String

Template editing URL.

user_id

String

User ID.

user_name

String

User name.

domain_id

String

Tenant ID.

domain_name

String

Tenant name.

is_build_in

Boolean

Whether the template is a built-in template or not.

region

String

The region of the system template is Cloud Pipeline. The region of the custom template is the actual region.

project_id

String

Project ID.

project_name

String

Project name.

create_time

String

Creation time.

last_modify_time

String

Modification time.

is_watch

Boolean

Whether to follow.

description

String

Template description.

parameter

Array of TemplateParam objects

Template parameter.

flow

Map<String,Map<String,String>>

Flow orchestration details, which describe the serial and parallel relationships of jobs in each stage of a pipeline. A Map type value, key indicates the stage name. By default, the first stage is initial, the last stage is final, and other stages are identified by state_digit. The value is the ID of the task (identified by Task_digit) in the stage and the ID of the subsequent stage. This field is one of the basic orchestration data of a pipeline. It is advised to obtain the value from the template-based creation API on the pipeline web UI.

states

Map<String,TemplateState>

State orchestration details. It is a Map type value. This field is one of the basic orchestration data of a pipeline. It is advised to obtain the value from the template-based creation API on the pipeline web UI.

can_update

Boolean

Whether it can be modified.

can_delete

Boolean

Whether it can be deleted.

need_hub

Boolean

Whether a code repository is required.

Table 5 TemplateParam

Parameter

Type

Description

required

String

Whether the parameter is mandatory.

visible

String

Whether the parameter is visible.

name

String

Pipeline parameter name.

value

String

Pipeline parameter value.

description

String

Pipeline parameter description.

paramtype

String

Pipeline parameter type.

display_type

String

Pipeline parameter display type.

display_name

String

Pipeline parameter display name.

is_static

Boolean

Whether it is a static parameter.

is_default

Boolean

Whether it is a default parameter.

limits

Array of ParamTypeLimits objects

Data of the Array type.

constraints

Array of Constraint objects

Data of the Array type.

Table 6 ParamTypeLimits

Parameter

Type

Description

disable

String

Whether it is discarded.

name

String

Language name.

displayname

String

Language display name.

id

String

Policy ID.

language

String

Scanning language.

Table 7 Constraint

Parameter

Type

Description

type

String

Verification rule type.

value

String

Verification rule.

errormsg

String

Verification failure description.

Table 8 TemplateState

Parameter

Type

Description

type

String

Job type.

name

String

Job name.

module_or_template_id

String

Template job ID.

module_or_template_name

String

Template job name.

display_name

String

Job name displayed on the pipeline page.

dsl_method

String

Types of jobs that can be mounted to a pipeline.

parameters

Map<String,Object>

Job parameter, which is a value of map type.

is_manual_execution

Boolean

Whether to manually execute the job.

job_parameter_validate

Boolean

Whether to verify job parameters.

is_show_codehub_url

Boolean

Whether to display the code repository URL.

is_execute

Boolean

Whether to execute

job_id

String

ID of the executed job.

job_name

String

Name of the executed job.

project_id

String

ID of the project to which the job belongs.

execution_mode

String

This parameter controls the execution mode of jobs in a stage. If type is task, the value of execution_mode is null. If type is stage, the value of execution_mode can be parallel or serial.

Status code: 400

Table 9 Response body parameters

Parameter

Type

Description

error_msg

String

Error message.

error_code

String

Error code.

Example Requests

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

Example Responses

None

SDK Sample Code

The SDK sample code is as follows.

 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
37
# 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 = 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)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

OK

400

Bad request

401

Unauthorized

403

Forbidden

404

Not Found

Error Codes

See Error Codes.