1. 示例简介
华为云流水线CodeArtsPipeline服务可以帮助客户快速搭建和灵活编排从编译构建-代码检查-测试-部署的机制自动化持续交付能力,帮助研发团队有效减少手工操作和提升应用发布效率。
该示例展示如何通过 CodeArtsPipeline Python SDK 进行删除流水线操作。
2. 开发前准备
- 已 注册 华为云,并完成 实名认证 。
- 已获取华为云开发Python 软件开发工具包SDK,SDK版本号请参见SDK开发中心 。
- 已获取华为云账号对应的Access Key(AK)和Secret Access Key(SK)。请在华为云控制台“我的凭证 > 访问密钥”页面上创建和查看您的AK/SK。具体请参见 访问密钥 。
- 已在CodeArts平台创建流水线
3. 安装SDK
使用服务端SDK前,您需要安装“huaweicloud-sdk-codeartspipeline”,具体的SDK版本号请参见 SDK开发中心 。
使用pip install安装华为云流水线Python SDK,执行如下命令安装相关依赖库,命令如下:
pip install huaweicloudsdkcodeartspipeline
4. 示例代码
import os
from huaweicloudsdkcodeartspipeline.v2.codeartspipeline_client import CodeArtsPipelineClient
from huaweicloudsdkcodeartspipeline.v2.model.delete_pipeline_request import DeletePipelineRequest
from huaweicloudsdkcodeartspipeline.v2.region.codeartspipeline_region import CodeArtsPipelineRegion
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcore.exceptions.exceptions import ClientRequestException
from huaweicloudsdkcore.exceptions.exceptions import ServerResponseException
class DeletePipelineDemo:
def __init__(self):
pass
@staticmethod
def main(args):
# 初始化必要参数及客户端
# 认证用的ak和sk直接写到代码中有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;
# 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。
delete_pipe_ak, delete_pipe_sk = os.environ("HUAWEICLOUD_SDK_AK"), os.environ("HUAWEICLOUD_SDK_SK")
# delete_pipe_project_id 请使用华为云console->iam我的凭证->对应region所属项目的项目ID
delete_pipe_project_id = "<Corresponding region Iam Project Id>"
# 删除流水线所需请求的region信息、配置认证信息、创建服务客户端
delete_pipe_region = CodeArtsPipelineRegion.value_of(region_id="cn-north-4")
delete_pipe_auth = BasicCredentials(ak=delete_pipe_ak, sk=delete_pipe_sk, project_id=delete_pipe_project_id)
code_arts_pipeline_client = CodeArtsPipelineClient.new_builder()\
.with_credentials(credentials=delete_pipe_auth)\
.with_region(region=delete_pipe_region).build()
# 删除流水线
try:
print("start to delete a pipeline")
delete_pipeline_request = DeletePipelineRequest()
# 需要删除的流水线ID
pipeline_id = "<Pipeline ID that needs to be deleted>"
delete_pipeline_request.pipeline_id = pipeline_id
# 流水线所属的项目ID
code_arts_project_id = "<Project ID your pipeline belongs to>"
delete_pipeline_request.project_id = code_arts_project_id
delete_pipeline_response = code_arts_pipeline_client.delete_pipeline(delete_pipeline_request)
print("delete pipeline with projectId:%s, pipelineId:%s, result:%s" % (code_arts_project_id, pipeline_id, delete_pipeline_response))
print("deleted pipelineId: %s" % delete_pipeline_response.pipeline_id)
except (ClientRequestException, ServerResponseException) as e:
print(str(e.status_code))
if __name__ == "__main__":
DeletePipelineDemo().main(any)
相关参数说明如下所示:
- delete_pipe_ak:华为云账号Access Key。
- delete_pipe_sk:华为云账号Secret Access Key。
- delete_pipe_region:服务所在区域。
5. 参考
更多api及参数详细说明信息请参考如下链接流水线 CodeArtsPipeline Api详细说明文档 中的"流水线管理--新"目录下内容。
6. 修订记录
| 发布日期 | 文档版本 | 修订说明 |
|---|---|---|
| 2023-11-15 | 1.0 | 文档首次发布 |