更新时间:2024-06-14 GMT+08:00

查询模板详情

功能介绍

查询模板详情

调用方法

请参见如何调用API

URI

GET /v3/templates/{template_id}

表1 路径参数

参数

是否必选

参数类型

描述

template_id

String

模板ID

表2 Query参数

参数

是否必选

参数类型

描述

template_type

String

模板类型

source

String

接口调用方

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

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

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

template_id

String

模板ID

template_name

String

模板名字

template_type

String

模板类型

user_id

String

用户ID

user_name

String

用户名字

domain_id

String

租户ID

domain_name

String

租户名字

is_build_in

Boolean

是否内置模板

region

String

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类型数据。本字段为描述流水线基础编排数据之一,建议可通过流水线真实界面基于模板创建接口中获取

表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/6efb0b24e2e9489eb0e53ee12904a19e?template_type=deployMan

响应示例

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
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 ShowTemplateDetailSolution {

    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();
        ShowTemplateDetailRequest request = new ShowTemplateDetailRequest();
        request.withTemplateType("<template_type>");
        request.withSource("<source>");
        try {
            ShowTemplateDetailResponse response = client.showTemplateDetail(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
# 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 = ShowTemplateDetailRequest()
        request.template_type = "<template_type>"
        request.source = "<source>"
        response = client.show_template_detail(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
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.ShowTemplateDetailRequest{}
	request.TemplateType = "<template_type>"
	sourceRequest:= "<source>"
	request.Source = &sourceRequest
	response, err := client.ShowTemplateDetail(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

错误码

请参见错误码