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
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Definition: Project ID. For details, see Obtaining a Project ID. Constraints: N/A Value range: The value consists of 32 characters, including digits and letters. Default value: N/A |
template_id |
Yes |
String |
Definition: Template ID, which is the unique identifier of a template. Obtain the template ID by calling the API for querying templates. templates.id indicates the template ID. Constraints: N/A Value range: The value consists of 32 characters, including digits and letters. Default value: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
component_id |
No |
String |
Definition: Pipeline microservice ID. Obtain the ID by calling the API for querying microservices. data.id indicates the microservice ID. Constraints: N/A Value range: The value consists of 32 characters, including only digits and letters. Default value: N/A |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Definition: User token. Obtain a token (the value of the X-Subject-Token response header) by calling the IAM API forobtaining a user token. Constraints: N/A Value range: N/A Default value: N/A |
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: N/A Value range: Max. 1024 characters. Default value: N/A |
is_publish |
Yes |
Boolean |
Definition: Whether the pipeline is a change-triggered pipeline. Constraints: N/A Value range:
Default value: N/A |
sources |
Yes |
Array of CodeSource objects |
Parameter description: Pipeline source list. Constraints: N/A Value range: N/A Default value: N/A |
variables |
No |
Array of variables objects |
Parameter description: Pipeline parameter list. Constraints: N/A Value range: N/A Default value: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
type |
No |
String |
Definition: Pipeline source type. Currently, code and artifact are supported. Constraints: N/A Value range: N/A Default value: N/A |
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 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
git_type |
No |
String |
Definition: Code repository type. Constraints: N/A Value range:
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 |
Definition: Code repository alias. Constraints: N/A Value range: Enter a maximum of 128 characters. Only letters, digits, and underscores (_) are supported. Default value: N/A |
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 and increases in ascending order. Constraints: N/A Value range: N/A Default value: N/A |
type |
No |
String |
Definition: Parameter type. Constraints: N/A Value range:
Default value: N/A |
value |
No |
String |
Parameter description: Parameter value. Constraints: N/A Value range: Max. 8192 characters. Default value: N/A |
is_secret |
No |
Boolean |
Definition: Private parameter or not. Constraints: N/A Value range:
Default value: false. |
description |
No |
String |
Definition: Parameter description. Constraints: N/A Value range: Max. 512 characters. Default value: N/A |
is_runtime |
No |
Boolean |
Definition: Whether a parameter can be set at runtime. Constraints: N/A Value range:
Default value: false. |
is_reset |
No |
Boolean |
Definition: Whether to reset. If the auto-increment parameter is edited, the edited value is used. Otherwise, the last digit increases. Constraints: N/A Value range:
Default value: false. |
latest_value |
No |
String |
Definition: Value of the parameter in the last run. Constraints: N/A Value range: Max. 8,192 characters. Default value: N/A |
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
Parameter |
Type |
Description |
---|---|---|
pipeline_id |
String |
Definition: Pipeline ID. Obtain the ID by calling the API for querying pipelines. pipelines.pipelineId indicates the pipeline ID. Value range: The value consists of 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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot