电脑做网站怎么解析域名,大气企业网站织梦模板,企业网站前台静态模板,网站iis配置使用阿里云效#xff08;Alibaba Cloud DevOps#xff09;API操作流水线时#xff0c;需要注意以下几个方面#xff1a; 认证与授权 确保你已经获取了正确的访问凭证#xff08;AccessKey ID 和 AccessKey Secret#xff09;#xff0c;并且这些凭证具有足够的权限来执行…使用阿里云效Alibaba Cloud DevOpsAPI操作流水线时需要注意以下几个方面 认证与授权 确保你已经获取了正确的访问凭证AccessKey ID 和 AccessKey Secret并且这些凭证具有足够的权限来执行你需要的操作。可以通过阿里云的RAM资源访问管理控制台管理和分配这些权限。 API 调用限制 阿里云效API通常有调用频率限制QPS。确保在设计你的应用程序时考虑到这些限制以避免超出配额导致的调用失败。 错误处理 在使用API时要做好错误处理和异常捕获。阿里云效API会返回详细的错误信息包括错误代码和错误消息。需要根据这些信息来诊断问题并采取适当的措施。 API版本 确保你使用的API版本是最新的并且在代码中指定了正确的版本。如果API有更新或废弃需及时更新你的代码。 参数验证 在调用API前确保所有必需参数都已正确设置并且这些参数的值符合API文档中的要求。 安全性 在代码中不要硬编码敏感信息如AccessKey ID和AccessKey Secret。可以使用环境变量或其他安全存储方式来管理这些信息。 调试和日志 启用详细的日志记录和调试信息以便在出现问题时能够快速定位和解决问题。 资源管理 确保在使用API创建或修改资源时有相应的清理逻辑以避免不必要的资源浪费。 注意事项 阿里云子账户需要给策略权限 AliyunRDCFullAccess子账号需要加入云效企业内部并给足操作权限 文档 云效API接口 云效错误码
示例代码
使用python 创建 Pipeline_sample.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import os
import sysfrom typing import Listfrom alibabacloud_devops20210625.client import Client as devops20210625Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
from alibabacloud_devops20210625 import models as devops_20210625_models
from alibabacloud_tea_console.client import Client as ConsoleClientORGANIZATION_ID [云效企业ID]class Pipeline:def __init__(self):self.organization_id ORGANIZATION_IDpassstaticmethoddef create_client() - devops20210625Client:使用AKSK初始化账号Clientreturn: Clientthrows Exception# 工程代码泄露可能会导致 AccessKey 泄露并威胁账号下所有资源的安全性。以下代码示例仅供参考。# 建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378659.html。config open_api_models.Config(# 必填请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,access_key_idos.environ[ALIBABA_CLOUD_ACCESS_KEY_ID],# 必填请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,access_key_secretos.environ[ALIBABA_CLOUD_ACCESS_KEY_SECRET])# Endpoint 请参考 https://api.aliyun.com/product/devopsconfig.endpoint fdevops.cn-hangzhou.aliyuncs.comreturn devops20210625Client(config)create_pipelinestaticmethoddef create_pipeline(name: str, yaml_file_path: str) - None:# 读取 YAML 文件内容with open(yaml_file_path, r) as file:content file.read()client Pipeline.create_client()create_pipeline_request devops_20210625_models.CreatePipelineRequest(namename,contentcontent)runtime util_models.RuntimeOptions()headers {}try:# 复制代码运行请自行打印 API 的返回值response client.create_pipeline_with_options(ORGANIZATION_ID, create_pipeline_request, headers,runtime)# 如果API调用成功这里将处理并打印返回的数据if response:print(Pipeline created successfully.)# 假设返回的数据结构中包含一个status或类似字段来表示操作状态print(Response Data:, response)# print(response.body.__dict__)# 提取并打印 pipelinIdpipelinId response.body.pipelin_idprint(pipelinId)except Exception as error:# 此处仅做打印展示请谨慎对待异常处理在工程项目中切勿直接忽略异常。# 错误 messageprint(error.message)# 诊断地址print(error.data.get(Recommend))UtilClient.assert_as_string(error.message)staticmethoddef delete_pipeline(pipelin_id: str) - None:client Pipeline.create_client()runtime util_models.RuntimeOptions()headers {}try:# 复制代码运行请自行打印 API 的返回值response client.delete_pipeline_with_options(ORGANIZATION_ID, pipelin_id, headers, runtime)# 如果API调用成功这里将处理并打印返回的数据if response:print(Pipeline created successfully.)# 假设返回的数据结构中包含一个status或类似字段来表示操作状态print(Response Data:, response)except Exception as error:# 此处仅做打印展示请谨慎对待异常处理在工程项目中切勿直接忽略异常。# 错误 messageprint(error.message)# 诊断地址print(error.data.get(Recommend))UtilClient.assert_as_string(error.message)staticmethoddef get_pipelines_list() - None:client Pipeline.create_client()list_pipelines_request devops_20210625_models.ListPipelinesRequest(max_results10,next_token123)runtime util_models.RuntimeOptions()headers {}try:# 复制代码运行请自行打印 API 的返回值response client.list_pipelines_with_options(ORGANIZATION_ID, list_pipelines_request, headers, runtime)# 如果API调用成功这里将处理并打印返回的数据if response:print(Pipeline created successfully.)# 假设返回的数据结构中包含一个status或类似字段来表示操作状态print(Response Data:, response)except Exception as error:# 此处仅做打印展示请谨慎对待异常处理在工程项目中切勿直接忽略异常。# 错误 messageprint(error.message)# 诊断地址print(error.data.get(Recommend))UtilClient.assert_as_string(error.message)staticmethoddef run_pipeline(json_file_path: str, pipeline_id: str) - None:with open(json_file_path, r) as file:params json.load(file)client Pipeline.create_client()start_pipeline_run_request devops_20210625_models.StartPipelineRunRequest(# params{envs: {# UPDATE: ALL,# IMAGES:sjdlkfjslkdajf# }}paramsparams)runtime util_models.RuntimeOptions()headers {}try:resp client.start_pipeline_run_with_options(ORGANIZATION_ID, pipeline_id,start_pipeline_run_request, headers, runtime)ConsoleClient.log(UtilClient.to_jsonstring(resp))except Exception as error:# 此处仅做打印展示请谨慎对待异常处理在工程项目中切勿直接忽略异常。# 错误 messageprint(error.message)# 诊断地址print(error.data.get(Recommend))UtilClient.assert_as_string(error.message)if __name__ __main__:# 创建一个测试流水线# Pipeline.create_pipeline( name测试流水线test4, yaml_file_pathpipeline_content.yaml)# 删除指定的流水线# Pipeline.delete_pipeline(3263926)# 执行指定的流水线Pipeline.run_pipeline(pipeline_params.json,3260926)# 获取流水线列表# Pipeline.get_pipelines_list()
传参文件 pipeline_params.json
{envs: {UPDATE: ALL,IMAGES: sjdlkfjslkdajf}
}流水线yaml配置 pipeline_content.yaml
文件可以再流水线使用yaml模式编辑后替换
stages:vm_deploy_stage:name: 部署jobs:vm_deploy_job:name: 主机部署测试主机component: VMDeploywith:downloadArtifact: falseuseEncode: falsemachineGroup: eSa9wUssQfX799kgrun: /home/test.shartifactDownloadPath: executeUser: rootartifact: