Help Center/ CodeArts Pipeline/ API Reference/ API/ Pipeline Management/ Creating a Pipeline With a Template
Updated on 2025-03-25 GMT+08:00

Creating a Pipeline With a Template

Function

This API is used to create a pipeline using a template.

Calling Method

For details, see Calling APIs.

URI

POST /v5/{project_id}/api/pipeline-templates/{template_id}/create-pipeline

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Parameter description:

CodeArts project ID.

Constraints:

N/A.

Value Range:

The value contains 32 characters.

Default value:

N/A.

template_id

Yes

String

Parameter description:

Pipeline template ID.

Constraints:

None.

Value range:

32 characters, including only digits and letters.

Default value:

None.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

component_id

No

String

Parameter description:

Pipeline microservice ID.

Constraints:

None.

Value range:

32 characters, including only digits and letters.

Default value:

None.

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Parameter description:

User token.

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

Constraints:

None.

Value range:

None.

Default value:

None.

Table 4 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Parameter description:

Pipeline name.

Constraints:

None.

Value range:

The value can contain only letters, digits, hyphens (-), and underscores (_). The length is 1128 characters.

Default value:

None.

description

No

String

Parameter description:

Pipeline description.

Constraints:

None.

Value range:

Up to 1024 characters.

Default value:

None.

is_publish

Yes

Boolean

Parameter description:

Whether the pipeline is a change-triggered pipeline.

Constraints:

None.

Value range:

true: this pipeline is a change-triggered pipeline; false: this pipeline is not a change-triggered pipeline.

Default value:

None.

sources

Yes

Array of CodeSource objects

Parameter description:

Pipeline source.

Constraints:

None.

Value range:

None.

Default value:

None.

variables

No

Array of variables objects

Parameter description:

Pipeline parameter list.

Constraints:

N/A

Value range:

N/A

Default value:

N/A

Table 5 CodeSource

Parameter

Mandatory

Type

Description

type

No

String

Parameter description:

Pipeline source type.

Constraints:

None.

Value range:

Currently, the code source type is supported.

Default value:

None.

params

No

params object

Parameter description:

Pipeline source parameters, including details about the pipeline source.

Constraints:

N/A

Value range:

N/A

Default value:

N/A

Table 6 params

Parameter

Mandatory

Type

Description

git_type

No

String

Parameter description:

Code repository type.

Constraints:

N/A

Value range:

CodeArts Repo, Gitee, GitHub, GitCode, and GitLab are supported.

Default value:

N/A

codehub_id

No

String

Parameter description:

CodeArts Repo code repository ID.

Constraints:

None.

Value range:

None.

Default value:

None.

endpoint_id

No

String

Parameter description:

Code source endpoint ID.

Constraints:

None.

Value range:

None.

Default value:

None.

default_branch

No

String

Parameter description:

Default branch.

Constraints:

None.

Value range:

None.

Default value:

None.

git_url

No

String

Parameter description:

HTTPS address of the Git repository, for example, https://example.com/CloudPipelinezycs00001/2000.git.

Constraints:

None.

Value range:

None.

Default value:

None.

ssh_git_url

No

String

Parameter description:

ssh_git address, for example, https://example.com/CloudPipelinezycs00001/2000.git.

Constraints:

None.

Value range:

None.

Default value:

None.

web_url

No

String

Parameter description:

Web page URL.

Constraints:

None.

Value range:

None.

Default value:

None.

repo_name

No

String

Parameter description:

Pipeline source name.

Constraints:

None.

Value range:

None.

Default value:

None.

alias

No

String

Parameter description:

Code repository alias. The value can contain a maximum of 128 characters, including letters, digits, and underscores (_).

Constraints:

None.

Value range:

None.

Default value:

None.

Table 7 variables

Parameter

Mandatory

Type

Description

name

No

AnyType

Parameter description:

Parameter name.

Constraints:

None.

Value range:

None.

Default value:

None.

sequence

No

Integer

Parameter description:

Parameter sequence number, which starts from 1.

Constraints:

None.

Value range:

None.

Default value:

None.

type

No

String

Parameter description:

Parameter type.

Constraints:

None.

Value range:

autoIncrement: auto-increment parameter; enum: enumeration parameter; string: character string parameter.

Default value:

None.

value

No

String

Parameter description:

Parameter value.

Constraints:

None.

Value range:

Up to 8192 characters.

Default value:

None.

is_secret

No

Boolean

Parameter description:

Whether the parameter is private.

Constraints:

None.

Value range:

true: private parameter; false: non-private parameter.

Default value:

false.

description

No

String

Parameter description:

Parameter description.

Constraints:

None.

Value range:

Up to 1024 characters.

Default value:

None.

is_runtime

No

Boolean

Parameter description:

Whether the parameter can be set during runtime.

Constraints:

None.

Value range:

true: the parameter can be set during runtime; false: the parameter cannot be set during runtime.

Default value:

false.

is_reset

No

Boolean

Parameter description:

Whether to reset. If the auto-increment parameter is edited, the edited value is used. Otherwise, the last digit increases.

Constraints:

None.

Value range:

true: use the edited parameter value; false: use the auto-increment parameter.

Default value:

false

latest_value

No

String

Parameter description:

Latest parameter value.

Constraints:

None.

Value range:

Up to 8192 characters.

Default value:

None.

limits

No

Array of strings

Parameter description:

List of enumerated values.

Constraints:

None.

Value range:

Up to 1,024 characters.

Default value:

None.

Response Parameters

Status code: 200

Table 8 Response body parameters

Parameter

Type

Description

pipeline_id

String

Parameter description:

Pipeline ID.

Value range:

32 characters, including only digits and letters.

Example Requests

Create a pipeline based on a template.

Set the pipeline name to New pipeline-2023041516464511, code repository to test001.git, and default branch to master.

POST https://{endpoint}/v5/54f90b75fc1447b1b65e8d3a9f77923d/api/pipeline-templates/434d660a96de423a935a0571c2223bca/create-pipeline

{
  "name" : "New Pipeline - 2023041516464511",
  "description" : "",
  "is_publish" : false,
  "sources" : [ {
    "type" : "code",
    "params" : {
      "git_type" : "codehub",
      "codehub_id" : "2111717853",
      "endpoint_id" : "",
      "default_branch" : "master",
      "git_url" : "https://example.com/cjrTest00002/test001.git",
      "ssh_git_url" : "git@example.com:cjrTest00002/test001.git",
      "web_url" : "",
      "repo_name" : "test001",
      "alias" : ""
    }
  } ]
}

Example Responses

Status code: 200

OK

{
  "pipeline_id" : "ad6b7f66283a45be9c1f82b06c831e59"
}

SDK Sample Code

The SDK sample code is as follows.

Create a pipeline based on a template.

Set the pipeline name to New pipeline-2023041516464511, code repository to test001.git, and default branch to master.

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

    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();
        CreatePipelineByTemplateIdRequest request = new CreatePipelineByTemplateIdRequest();
        request.withTemplateId("{template_id}");
        request.withProjectId("{project_id}");
        PipelineByTemplateDTO body = new PipelineByTemplateDTO();
        CodeSourceParams paramsSources = new CodeSourceParams();
        paramsSources.withGitType("codehub")
            .withCodehubId("2111717853")
            .withEndpointId("")
            .withDefaultBranch("master")
            .withGitUrl("https://example.com/cjrTest00002/test001.git")
            .withSshGitUrl("git@example.com:cjrTest00002/test001.git")
            .withWebUrl("")
            .withRepoName("test001")
            .withAlias("");
        List<CodeSource> listbodySources = new ArrayList<>();
        listbodySources.add(
            new CodeSource()
                .withType("code")
                .withParams(paramsSources)
        );
        body.withSources(listbodySources);
        body.withIsPublish(false);
        body.withDescription("");
        body.withName("New Pipeline - 2023041516464511");
        request.withBody(body);
        try {
            CreatePipelineByTemplateIdResponse response = client.createPipelineByTemplateId(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());
        }
    }
}

Create a pipeline based on a template.

Set the pipeline name to New pipeline-2023041516464511, code repository to test001.git, and default branch to master.

 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
# 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 = CreatePipelineByTemplateIdRequest()
        request.template_id = "{template_id}"
        request.project_id = "{project_id}"
        paramsSources = CodeSourceParams(
            git_type="codehub",
            codehub_id="2111717853",
            endpoint_id="",
            default_branch="master",
            git_url="https://example.com/cjrTest00002/test001.git",
            ssh_git_url="git@example.com:cjrTest00002/test001.git",
            web_url="",
            repo_name="test001",
            alias=""
        )
        listSourcesbody = [
            CodeSource(
                type="code",
                params=paramsSources
            )
        ]
        request.body = PipelineByTemplateDTO(
            sources=listSourcesbody,
            is_publish=False,
            description="",
            name="New Pipeline - 2023041516464511"
        )
        response = client.create_pipeline_by_template_id(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Create a pipeline based on a template.

Set the pipeline name to New pipeline-2023041516464511, code repository to test001.git, and default branch to master.

 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
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.CreatePipelineByTemplateIdRequest{}
	request.TemplateId = "{template_id}"
	request.ProjectId = "{project_id}"
	gitTypeParams:= "codehub"
	codehubIdParams:= "2111717853"
	endpointIdParams:= ""
	defaultBranchParams:= "master"
	gitUrlParams:= "https://example.com/cjrTest00002/test001.git"
	sshGitUrlParams:= "git@example.com:cjrTest00002/test001.git"
	webUrlParams:= ""
	repoNameParams:= "test001"
	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,
        },
    }
	descriptionPipelineByTemplateDto:= ""
	request.Body = &model.PipelineByTemplateDto{
		Sources: listSourcesbody,
		IsPublish: false,
		Description: &descriptionPipelineByTemplateDto,
		Name: "New Pipeline - 2023041516464511",
	}
	response, err := client.CreatePipelineByTemplateId(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

401

Unauthorized

403

Forbidden

404

Not Found

Error Codes

See Error Codes.