更新时间:2024-12-06 GMT+08:00
分享

获取流水线列表

功能介绍

获取流水线列表接口

调用方法

请参见如何调用API

URI

POST /v3/pipelines/list

请求参数

表1 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

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

表2 请求Body参数

参数

是否必选

参数类型

描述

pipeline_name

String

流水线名字。查询时进行模糊匹配。

project_ids

String

项目id,有多个值时用逗号分隔,id个数取值[0,10],非必选。如果该参数有值,则获取对应项目下的流水线列表;如果没有值,则获取用户有权限的所有项目的流水线列表

creator_ids

String

创建人id,有多个值时用逗号分隔,id个数取值[0,10],非必选

executor_ids

String

执行人id。有多个值时用逗号分隔,id个数取值[0,10],非必选

status

String

流水线运行状态。取值及含义:waiting:等待;running:执行中;verifying:待审核;suspending:挂起;completed:完成。

outcome

String

流水线执行结果。取值及含义:success:成功;error:失败;aborted:终止

sort_key

String

用于排序的字段。取值为:pipeline_name,create_time,start_time

sort_dir

String

排序方式。asc按排序字段升序,desc按排序字段降序

git_url

String

代码仓地址。仅支持codehub仓库,如:git@codehub.XXX.git

offset

Integer

偏移量。表示从此偏移量开始查询,offset大于等于0,默认取值为0

limit

Integer

每次查询的条目数量。取值[10-50],默认取值为10

响应参数

状态码: 200

表3 响应Body参数

参数

参数类型

描述

offset

Integer

偏移量,表示从此偏移量开始查询,offset大于等于0

limit

Integer

每次查询的条目数量

total

Integer

总条目数量

result

Array of PipelineBasicInfo objects

流水线列表

表4 PipelineBasicInfo

参数

参数类型

描述

project_id

String

项目id

project_name

String

项目名称

pipeline_id

String

流水线id

pipeline_name

String

流水线名称

creator_id

String

流水线创建人id

creator_name

String

流水线创建人名字

executor_id

String

流水线执行人id

executor_name

String

流水线执行人名字

start_time

String

启动时间

create_time

String

创建时间

watched

String

用户是否关注流水线:true(关注),false(未关注)

状态码: 400

表5 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

不涉及。

请求示例

获取流水线列表。

指定查询的项目ID为”e12ed176898d4841aa9881fe9b933c87”,创建人ID为”847a5317086c41798469d0868535943a”,并根据流水线名称降序排序。

POST https://{endpoint}/v3/pipelines/list

{
  "pipeline_name" : "",
  "project_ids" : "e12ed176898d4841aa9881fe9b933c87",
  "creator_ids" : "847a5317086c41798469d0868535943a",
  "executor_ids" : "847a5317086c41798469d0868535943a",
  "status" : "waiting,running,verifying,handling,suspending,completed",
  "outcome" : "error,success,aborted",
  "sort_key" : "pipeline_name",
  "sort_dir" : "desc",
  "git_url" : "",
  "offset" : 4,
  "limit" : 10
}

响应示例

状态码: 200

OK

{
  "offset" : 0,
  "limit" : 10,
  "total" : 88,
  "result" : [ {
    "project_id" : "e12ed176898d4841aa9881fe9b933c87",
    "project_name" : "Pipeline_Beta_自动测试",
    "pipeline_id" : "d33f98177c3e44f8841b005e1badcaed",
    "pipeline_name" : "马云多仓",
    "creator_id" : "847a5317086c41798469d0868535943a",
    "creator_name" : "大Beta测试账号",
    "executor_id" : "847a5317086c41798469d0868535943a",
    "executor_name" : "大Beta测试账号",
    "start_time" : "2022-09-08 17:08:02",
    "create_time" : "2022-07-28 17:02:11",
    "watched" : "true"
  }, {
    "project_id" : "e12ed176898d4841aa9881fe9b933c87",
    "project_name" : "Pipeline_Beta_自动测试",
    "pipeline_id" : "2ec08a45031c4d2896292a48b7fb1a30",
    "pipeline_name" : "门禁专用测试_勿删",
    "creator_id" : "847a5317086c41798469d0868535943a",
    "creator_name" : "大Beta测试账号",
    "executor_id" : "847a5317086c41798469d0868535943a",
    "executor_name" : "大Beta测试账号",
    "start_time" : "2022-09-08 16:52:03",
    "create_time" : "2020-10-29 17:05:02",
    "watched" : "true"
  } ]
}

SDK代码示例

SDK代码示例如下。

获取流水线列表。

指定查询的项目ID为”e12ed176898d4841aa9881fe9b933c87”,创建人ID为”847a5317086c41798469d0868535943a”,并根据流水线名称降序排序。

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

    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();
        ListPipelineSimpleInfoRequest request = new ListPipelineSimpleInfoRequest();
        ListPipelineSimpleInfoRequestBody body = new ListPipelineSimpleInfoRequestBody();
        body.withLimit(10);
        body.withOffset(4);
        body.withGitUrl("");
        body.withSortDir("desc");
        body.withSortKey("pipeline_name");
        body.withOutcome("error,success,aborted");
        body.withStatus("waiting,running,verifying,handling,suspending,completed");
        body.withExecutorIds("847a5317086c41798469d0868535943a");
        body.withCreatorIds("847a5317086c41798469d0868535943a");
        body.withProjectIds("e12ed176898d4841aa9881fe9b933c87");
        body.withPipelineName("");
        request.withBody(body);
        try {
            ListPipelineSimpleInfoResponse response = client.listPipelineSimpleInfo(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());
        }
    }
}

获取流水线列表。

指定查询的项目ID为”e12ed176898d4841aa9881fe9b933c87”,创建人ID为”847a5317086c41798469d0868535943a”,并根据流水线名称降序排序。

 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
# 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 = ListPipelineSimpleInfoRequest()
        request.body = ListPipelineSimpleInfoRequestBody(
            limit=10,
            offset=4,
            git_url="",
            sort_dir="desc",
            sort_key="pipeline_name",
            outcome="error,success,aborted",
            status="waiting,running,verifying,handling,suspending,completed",
            executor_ids="847a5317086c41798469d0868535943a",
            creator_ids="847a5317086c41798469d0868535943a",
            project_ids="e12ed176898d4841aa9881fe9b933c87",
            pipeline_name=""
        )
        response = client.list_pipeline_simple_info(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

获取流水线列表。

指定查询的项目ID为”e12ed176898d4841aa9881fe9b933c87”,创建人ID为”847a5317086c41798469d0868535943a”,并根据流水线名称降序排序。

 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
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.ListPipelineSimpleInfoRequest{}
	limitListPipelineSimpleInfoRequestBody:= int32(10)
	offsetListPipelineSimpleInfoRequestBody:= int32(4)
	gitUrlListPipelineSimpleInfoRequestBody:= ""
	sortDirListPipelineSimpleInfoRequestBody:= "desc"
	sortKeyListPipelineSimpleInfoRequestBody:= "pipeline_name"
	outcomeListPipelineSimpleInfoRequestBody:= "error,success,aborted"
	statusListPipelineSimpleInfoRequestBody:= "waiting,running,verifying,handling,suspending,completed"
	executorIdsListPipelineSimpleInfoRequestBody:= "847a5317086c41798469d0868535943a"
	creatorIdsListPipelineSimpleInfoRequestBody:= "847a5317086c41798469d0868535943a"
	projectIdsListPipelineSimpleInfoRequestBody:= "e12ed176898d4841aa9881fe9b933c87"
	pipelineNameListPipelineSimpleInfoRequestBody:= ""
	request.Body = &model.ListPipelineSimpleInfoRequestBody{
		Limit: &limitListPipelineSimpleInfoRequestBody,
		Offset: &offsetListPipelineSimpleInfoRequestBody,
		GitUrl: &gitUrlListPipelineSimpleInfoRequestBody,
		SortDir: &sortDirListPipelineSimpleInfoRequestBody,
		SortKey: &sortKeyListPipelineSimpleInfoRequestBody,
		Outcome: &outcomeListPipelineSimpleInfoRequestBody,
		Status: &statusListPipelineSimpleInfoRequestBody,
		ExecutorIds: &executorIdsListPipelineSimpleInfoRequestBody,
		CreatorIds: &creatorIdsListPipelineSimpleInfoRequestBody,
		ProjectIds: &projectIdsListPipelineSimpleInfoRequestBody,
		PipelineName: &pipelineNameListPipelineSimpleInfoRequestBody,
	}
	response, err := client.ListPipelineSimpleInfo(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

错误码

请参见错误码

相关文档