Creating a Pipeline
Function
This API is used to create a pipeline.
Calling Method
For details, see Calling APIs.
URI
POST /v5/{project_id}/api/pipelines
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
component_id |
No |
String |
Component ID. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
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. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
Yes |
String |
Pipeline name. |
description |
No |
String |
Pipeline description. |
is_publish |
Yes |
Boolean |
Whether the pipeline is a release pipeline. |
sources |
No |
Array of CodeSource objects |
Pipeline source. |
variables |
No |
Array of CustomVariable objects |
Pipeline custom global variables. |
schedules |
No |
Array of PipelineSchedule objects |
Pipeline scheduled execution configuration. |
triggers |
No |
Array of PipelineTrigger objects |
Pipeline code event triggering configuration. |
manifest_version |
No |
String |
Pipeline structure definition version. Default: 3.0. (New version) |
definition |
Yes |
String |
Pipeline structure definition. |
project_name |
No |
String |
Project name. |
group_id |
No |
String |
Pipeline group ID. |
id |
No |
String |
In the replication scenario, the value is the original pipeline ID. |
concurrency_control |
No |
PipelineConcurrencyMgmt object |
Pipeline parallel policy management |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
type |
No |
String |
Pipeline source type. |
params |
No |
params object |
Pipeline source parameters. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
git_type |
No |
String |
Git type. |
codehub_id |
No |
String |
Repo repository ID. |
endpoint_id |
No |
String |
Endpoint ID. |
default_branch |
No |
String |
Default branch. |
git_url |
No |
String |
Git URL. |
ssh_git_url |
No |
String |
SSH_Git URL. |
web_url |
No |
String |
Web URL. |
repo_name |
No |
String |
Pipeline source name. |
alias |
No |
String |
Code repository alias. The alias can contain a maximum of 128 characters, including letters, digits, and underscores (_). |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
pipeline_id |
No |
String |
Pipeline ID. |
name |
No |
String |
Custom parameter name. |
sequence |
No |
Integer |
Custom parameter sequence. |
type |
No |
String |
Custom parameter type. |
value |
No |
String |
Default values of custom parameters. |
is_secret |
No |
Boolean |
Private parameter or not. |
description |
No |
String |
Custom parameter description. |
is_runtime |
No |
Boolean |
Runtime setting or not. |
limits |
No |
Array of objects |
Limited enumerated value. |
is_reset |
No |
Boolean |
Reset or not. |
latest_value |
No |
String |
Latest parameter value. |
runtime_value |
No |
String |
Runtime input value. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
uuid |
No |
String |
Job ID. |
type |
No |
String |
Job type. |
name |
No |
String |
Job name. |
enable |
No |
String |
Available or not. |
days_of_week |
No |
Array of integers |
Specific time in one week. |
time_zone |
No |
String |
Time zone. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
pipeline_id |
No |
String |
Pipeline ID. |
git_url |
No |
String |
Git URL. |
git_type |
No |
String |
Git type. |
is_auto_commit |
No |
Boolean |
Whether to automatically commit. |
events |
No |
Array of CodeEvent objects |
Event. |
hook_id |
No |
String |
Callback ID. |
repo_id |
No |
String |
Repository ID. |
endpoint_id |
No |
String |
Endpoint ID. |
callback_url |
No |
String |
Callback URL. |
security_token |
No |
String |
User token. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
type |
No |
String |
Event type. |
enable |
No |
Boolean |
Available or not. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
pipeline_id |
No |
String |
Pipeline ID. |
concurrency_number |
No |
Integer |
Parallel number. |
exceed_action |
No |
String |
Policy for exceeding the allowed parallel number. |
create_time |
No |
Long |
Creation time. |
update_time |
No |
Long |
Update time. |
enable |
No |
Boolean |
Whether it is valid. |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
pipeline_id |
String |
Pipeline ID. |
Example Requests
POST https://{endpoint}/v5/d80a8a6530324b7bac972cbb8a9f28ec/api/pipelines { "name" : "New Pipeline-20231024204112", "description" : "", "is_publish" : false, "sources" : [ { "type" : "code", "params" : { "git_type" : "codehub", "codehub_id" : "2111699317", "endpoint_id" : "", "default_branch" : "master", "git_url" : "https://example.com/0213yjw100001/0213yjw1-android.git", "ssh_git_url" : "git@example.com:0213yjw100001/0213yjw1-android.git", "web_url" : "", "repo_name" : "0213yjw1-android", "alias" : "" } } ], "definition" : "{\"stages\": [_1\",\"sequence\":\"0\",\"jobs\":[{\"id\":\"\",\"stage_id\":1698151278179,\"identifier\":\"1698151278179f6548479-2eaf-420a-92a4-92d9a711c51b\",\"name\": \"Create Task in the {\"id\":1698151278179,\"identifier\":\"169815127817987dd9f1d-7821-46e4-89be-2a95b01b0533\",\"run_always\":false,\"name\": \"Phase\",\"depends_on\":[] ,\"timeout\":\"\",\"timeout_unit\":\"\",\"steps\":[],\"exec_type\":\"AGENTLESS_JOB\",\"sequence\":0}],\"rule_templates\":[],\"pre\":[{\"task\":\"official_devcloud_autoTrigger\",\"sequence\":0}],\"post\":[],\"depends_on\":[]}]}" }
Example Responses
Status code: 200
OK
{ "pipeline_id" : "8bfbd69eac154a0da341705a36294aca" }
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 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 CreatePipelineNewSolution { 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(); CreatePipelineNewRequest request = new CreatePipelineNewRequest(); request.withComponentId("<component_id>"); PipelineDTO body = new PipelineDTO(); CodeSourceParams paramsSources = new CodeSourceParams(); paramsSources.withGitType("codehub") .withCodehubId("2111699317") .withEndpointId("") .withDefaultBranch("master") .withGitUrl("https://example.com/0213yjw100001/0213yjw1-android.git") .withSshGitUrl("git@example.com:0213yjw100001/0213yjw1-android.git") .withWebUrl("") .withRepoName("0213yjw1-android") .withAlias(""); List<CodeSource> listbodySources = new ArrayList<>(); listbodySources.add( new CodeSource() .withType("code") .withParams(paramsSources) ); body.withDefinition("{"stages": [_1","sequence":"0","jobs":[{"id":"","stage_id":1698151278179,"identifier":"1698151278179f6548479-2eaf-420a-92a4-92d9a711c51b","name": "Create Task in the {"id":1698151278179,"identifier":"169815127817987dd9f1d-7821-46e4-89be-2a95b01b0533","run_always":false,"name": "Phase","depends_on":[] ,"timeout":"","timeout_unit":"","steps":[],"exec_type":"AGENTLESS_JOB","sequence":0}],"rule_templates":[],"pre":[{"task":"official_devcloud_autoTrigger","sequence":0}],"post":[],"depends_on":[]}]}"); body.withSources(listbodySources); body.withIsPublish(false); body.withDescription(""); body.withName("New Pipeline-20231024204112"); request.withBody(body); try { CreatePipelineNewResponse response = client.createPipelineNew(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 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 = CreatePipelineNewRequest() request.component_id = "<component_id>" paramsSources = CodeSourceParams( git_type="codehub", codehub_id="2111699317", endpoint_id="", default_branch="master", git_url="https://example.com/0213yjw100001/0213yjw1-android.git", ssh_git_url="git@example.com:0213yjw100001/0213yjw1-android.git", web_url="", repo_name="0213yjw1-android", alias="" ) listSourcesbody = [ CodeSource( type="code", params=paramsSources ) ] request.body = PipelineDTO( definition="{"stages": [_1","sequence":"0","jobs":[{"id":"","stage_id":1698151278179,"identifier":"1698151278179f6548479-2eaf-420a-92a4-92d9a711c51b","name": "Create Task in the {"id":1698151278179,"identifier":"169815127817987dd9f1d-7821-46e4-89be-2a95b01b0533","run_always":false,"name": "Phase","depends_on":[] ,"timeout":"","timeout_unit":"","steps":[],"exec_type":"AGENTLESS_JOB","sequence":0}],"rule_templates":[],"pre":[{"task":"official_devcloud_autoTrigger","sequence":0}],"post":[],"depends_on":[]}]}", sources=listSourcesbody, is_publish=False, description="", name="New Pipeline-20231024204112" ) response = client.create_pipeline_new(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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
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.CreatePipelineNewRequest{} componentIdRequest:= "<component_id>" request.ComponentId = &componentIdRequest gitTypeParams:= "codehub" codehubIdParams:= "2111699317" endpointIdParams:= "" defaultBranchParams:= "master" gitUrlParams:= "https://example.com/0213yjw100001/0213yjw1-android.git" sshGitUrlParams:= "git@example.com:0213yjw100001/0213yjw1-android.git" webUrlParams:= "" repoNameParams:= "0213yjw1-android" 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, }, } descriptionPipelineDto:= "" request.Body = &model.PipelineDto{ Definition: "{"stages": [_1","sequence":"0","jobs":[{"id":"","stage_id":1698151278179,"identifier":"1698151278179f6548479-2eaf-420a-92a4-92d9a711c51b","name": "Create Task in the {"id":1698151278179,"identifier":"169815127817987dd9f1d-7821-46e4-89be-2a95b01b0533","run_always":false,"name": "Phase","depends_on":[] ,"timeout":"","timeout_unit":"","steps":[],"exec_type":"AGENTLESS_JOB","sequence":0}],"rule_templates":[],"pre":[{"task":"official_devcloud_autoTrigger","sequence":0}],"post":[],"depends_on":[]}]}", Sources: &listSourcesbody, IsPublish: false, Description: &descriptionPipelineDto, Name: "New Pipeline-20231024204112", } response, err := client.CreatePipelineNew(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