当前位置: 首页 > news >正文

阿里云云效对接SDK获取流水线制品

参考文档:

API旧版 企业令牌 https://help.aliyun.com/zh/yunxiao/developer-reference/api-reference
API新版 个人令牌 https://help.aliyun.com/zh/yunxiao/developer-reference/api-reference-standard-proprietary
API 个人令牌 https://www.alibabacloud.com/help/zh/yunxiao/developer-reference/api-reference-standard-proprietary
API调试 https://api.aliyun.com/api/devops/2021-06-25/ListPipelines
API调试文档 https://api.aliyun.com/document/devops/2021-06-25/ListPipelineRuns
RAM用户权限策略添加 AliyunRDCFullAccess

v1版sdk

pom引入

 <!--云效v1 --><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-devops</artifactId><version>1.0.7</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.6.0</version></dependency>

工具类

package com.vvvtimes;import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;public class Yunxiaov1Api {private static String regionId = "cn-hangzhou";private static String endpoint = "devops.cn-hangzhou.aliyuncs.com";private static String accessKey = "aaa";private static String accessSecret = "bbb";private static String organizationId = "ccc";private static String pipelineId = "3646953";private static String pipelineRunId = "59";//ListOrganizations 获取组织列表public static String ListOrganizations() {IClientProfile profile = DefaultProfile.getProfile(regionId,accessKey,accessSecret);DefaultAcsClient client = new DefaultAcsClient(profile);CommonRequest request = new CommonRequest();request.setMethod(MethodType.GET);request.setDomain(endpoint);request.setVersion("2021-06-25");request.setUriPattern("/users/joinedOrgs");request.putHeadParameter("Content-Type", "application/json");try {CommonResponse response = client.getCommonResponse(request);return response.getData();} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}return null;}//ListPipelines 获取流水线列表//https://api.aliyun.com/api/devops/2021-06-25/ListPipelines?spm=api-workbench.API%20Document.0.0.11aa51cfP4tP38&RegionId=cn-hangzhoupublic static String ListPipelines() {IClientProfile profile = DefaultProfile.getProfile(regionId,accessKey,accessSecret);DefaultAcsClient client = new DefaultAcsClient(profile);CommonRequest request = new CommonRequest();request.setMethod(MethodType.GET);request.setDomain(endpoint);request.setVersion("2021-06-25");// 使用 putPathParameter 替换路径参数request.putPathParameter("organizationId", organizationId);request.setUriPattern("/organization/[organizationId]/pipelines");request.putHeadParameter("Content-Type", "application/json");try {CommonResponse response = client.getCommonResponse(request);return response.getData();} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}return null;}// ListPipelineRuns 获取流水线运行示例列表 -->API错误403public static String ListPipelineRuns() {IClientProfile profile = DefaultProfile.getProfile(regionId,accessKey,accessSecret);DefaultAcsClient client = new DefaultAcsClient(profile);CommonRequest request = new CommonRequest();//request.setProtocol(ProtocolType.HTTPS);request.setMethod(MethodType.GET);request.setDomain(endpoint);request.setVersion("2021-06-25");// 使用 putPathParameter 替换路径参数request.putPathParameter("organizationId", organizationId);request.putPathParameter("pipelineId", pipelineId);request.setUriPattern("/organization/[organizationId]/pipelines/[pipelineId]/pipelineRuns");request.putQueryParameter("maxResults", "10");request.putQueryParameter("nextToken", "aaaaaa");request.putHeadParameter("Content-Type", "application/json");try {CommonResponse response = client.getCommonResponse(request);return response.getData();} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}return null;}//GetPipelineRun 获取流水线单个运行示例详情 -->403public static String GetPipelineRun() throws Exception {IClientProfile profile = DefaultProfile.getProfile(regionId,accessKey,accessSecret);DefaultAcsClient client = new DefaultAcsClient(profile);CommonRequest request = new CommonRequest();//request.setProtocol(ProtocolType.HTTPS);request.setMethod(MethodType.GET);request.setDomain("devops.cn-hangzhou.aliyuncs.com");request.setVersion("2021-06-25");// 使用 putPathParameter 替换路径参数request.putPathParameter("organizationId", organizationId);request.putPathParameter("pipelineId", pipelineId);request.setUriPattern("/organization/[organizationId]/pipelines/[pipelineId]/pipelineRuns/59");request.putHeadParameter("Content-Type", "application/json");try {CommonResponse response = client.getCommonResponse(request);return response.getData();} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}return null;}//获取流水线制品URLpublic static String GetPipelineArtifactUrl() throws Exception {IClientProfile profile = DefaultProfile.getProfile(regionId,accessKey,accessSecret);DefaultAcsClient client = new DefaultAcsClient(profile);CommonRequest request = new CommonRequest();//request.setProtocol(ProtocolType.HTTPS);request.setMethod(MethodType.POST);request.setDomain("devops.cn-hangzhou.aliyuncs.com");request.setVersion("2021-06-25");// 使用 putPathParameter 替换路径参数request.putPathParameter("organizationId", organizationId);request.setUriPattern("/organization/[organizationId]/pipeline/getArtifactDownloadUrl");request.putQueryParameter("filePath", "aone2/2435041/1748354328689/Artifacts_3646953.tgz");request.putQueryParameter("fileName", "Artifacts_3646953.tgz");request.putHeadParameter("Content-Type", "application/json");try {CommonResponse response = client.getCommonResponse(request);return response.getData();} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}return null;}
}

示例调用

package com.vvvtimes;/*
/*** Hello world!**/
public class App {public static void main(String[] args) throws Exception {String s = Yunxiaov1Api.GetPipelineArtifactUrl();System.out.println(s);}
}

v2版sdk

pom引入

<!--云效v2 --><dependency><groupId>com.aliyun</groupId><artifactId>devops20210625</artifactId><version>5.0.1</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea-openapi</artifactId><version>0.3.8</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea-console</artifactId><version>0.0.1</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea-util</artifactId><version>0.2.23</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>credentials-java</artifactId><version>1.0.1</version></dependency>

v2工具类

package com.vvvtimes;import com.aliyun.devops20210625.models.*;
import com.aliyun.tea.TeaException;
import com.aliyun.teautil.Common;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;import java.util.Map;public class Yunxiaov2Api {private static String endpoint = "devops.cn-hangzhou.aliyuncs.com";private static String accessKey = "aaa";private static String accessSecret = "bbb";private static String organizationId = "ccc";private static String pipelineId = "3646953";private static String pipelineRunId = "59";//ListOrganizations 获取组织列表public static String ListOrganizations() throws Exception {com.aliyun.devops20210625.Client client = Yunxiaov2Api.createClient();com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();java.util.Map<String, String> headers = new java.util.HashMap<>();try {// 复制代码运行请自行打印 API 的返回值ListJoinedOrganizationsResponse resp = client.listJoinedOrganizationsWithOptions(headers, runtime);// 将整个响应转为 JSON 字符串String fullJson = Common.toJSONString(resp);// 提取 body 并返回return extractPipelineBody(fullJson);} catch (TeaException error) {System.out.println(error.getMessage());System.out.println(error.getData().get("Recommend"));} catch (Exception _error) {TeaException error = new TeaException(_error.getMessage(), _error);System.out.println(error.getMessage());}return null;}//ListPipelines 获取流水线列表//参考调用 https://api.aliyun.com/api/devops/2021-06-25/ListPipelines?spm=api-workbench.API%20Document.0.0.11aa51cfP4tP38&RegionId=cn-hangzhoupublic static String ListPipelines() throws Exception {com.aliyun.devops20210625.Client client = Yunxiaov2Api.createClient();com.aliyun.devops20210625.models.ListPipelinesRequest listPipelinesRequest = new com.aliyun.devops20210625.models.ListPipelinesRequest().setNextToken("aaaaaaaaaa").setMaxResults(30L);com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();java.util.Map<String, String> headers = new java.util.HashMap<>();try {com.aliyun.devops20210625.models.ListPipelinesResponse resp = client.listPipelinesWithOptions(organizationId, listPipelinesRequest, headers, runtime);// 将整个响应转为 JSON 字符串String fullJson = Common.toJSONString(resp);// 提取 body 并返回return extractPipelineBody(fullJson);} catch (TeaException error) {System.out.println(error.getMessage());System.out.println(error.getData().get("Recommend"));} catch (Exception _error) {TeaException error = new TeaException(_error.getMessage(), _error);System.out.println(error.getMessage());}return null;}// ListPipelineRuns 获取流水线运行示例列表 -->API错误403public static String ListPipelineRuns() throws Exception {com.aliyun.devops20210625.Client client = Yunxiaov2Api.createClient();com.aliyun.devops20210625.models.ListPipelineRunsRequest listPipelineRunsRequest = new com.aliyun.devops20210625.models.ListPipelineRunsRequest().setMaxResults(10L).setNextToken("aaaaaa");com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();java.util.Map<String, String> headers = new java.util.HashMap<>();try {// 复制代码运行请自行打印 API 的返回值ListPipelineRunsResponse resp = client.listPipelineRunsWithOptions(organizationId, pipelineId, listPipelineRunsRequest, headers, runtime);// 将整个响应转为 JSON 字符串String fullJson = Common.toJSONString(resp);System.out.println(fullJson);// 提取 body 并返回return extractPipelineBody(fullJson);} catch (TeaException error) {System.out.println(error.getMessage());System.out.println(error.getData().get("Recommend"));} catch (Exception _error) {TeaException error = new TeaException(_error.getMessage(), _error);System.out.println(error.getMessage());}return null;}//GetPipelineRun 获取流水线单个运行示例详情 -->403public static String GetPipelineRun() throws Exception {com.aliyun.devops20210625.Client client = Yunxiaov2Api.createClient();com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();java.util.Map<String, String> headers = new java.util.HashMap<>();try {// 复制代码运行请自行打印 API 的返回值GetPipelineRunResponse resp = client.getPipelineRunWithOptions(organizationId, pipelineId, pipelineRunId, headers, runtime);// 将整个响应转为 JSON 字符串String fullJson = Common.toJSONString(resp);System.out.println(fullJson);// 提取 body 并返回return extractPipelineBody(fullJson);} catch (TeaException error) {System.out.println(error.getMessage());System.out.println(error.getData().get("Recommend"));} catch (Exception _error) {TeaException error = new TeaException(_error.getMessage(), _error);System.out.println(error.getMessage());}return null;}//获取流水线制品URLpublic static String GetPipelineArtifactUrl() throws Exception {com.aliyun.devops20210625.Client client = Yunxiaov2Api.createClient();com.aliyun.devops20210625.models.GetPipelineArtifactUrlRequest getPipelineArtifactUrlRequest = new com.aliyun.devops20210625.models.GetPipelineArtifactUrlRequest().setFileName("Artifacts_3646953.tgz").setFilePath("aone2/2435041/1748354328689/Artifacts_3646953.tgz");com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();java.util.Map<String, String> headers = new java.util.HashMap<>();try {// 复制代码运行请自行打印 API 的返回值GetPipelineArtifactUrlResponse resp = client.getPipelineArtifactUrlWithOptions(organizationId, getPipelineArtifactUrlRequest, headers, runtime);// 将整个响应转为 JSON 字符串String fullJson = Common.toJSONString(resp);System.out.println(fullJson);// 提取 body 并返回return extractPipelineBody(fullJson);} catch (TeaException error) {System.out.println(error.getMessage());System.out.println(error.getData().get("Recommend"));} catch (Exception _error) {TeaException error = new TeaException(_error.getMessage(), _error);System.out.println(error.getMessage());}return null;}/*** <b>description</b> :* <p>使用凭据初始化账号Client</p>** @return Client* @throws Exception*/public static com.aliyun.devops20210625.Client createClient() throws Exception {com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config().setAccessKeyId(accessKey)     // 替换为你的 AccessKey ID.setAccessKeySecret(accessSecret); // 替换为你的 Secretconfig.endpoint = endpoint;return new com.aliyun.devops20210625.Client(config);}public static String extractPipelineBody(String fullResponseJson) {// 将完整 JSON 转为 Map 结构java.util.Map<String, Object> fullResponseMap = (Map<String, Object>) Common.parseJSON(fullResponseJson);// 提取 body 部分Object body = fullResponseMap.get("body");// 再转成 JSON 字符串返回return Common.toJSONString(body);}}

v2调用示例

package com.vvvtimes;/*
/*** Hello world!**/
public class App {public static void main(String[] args) throws Exception {String s = Yunxiaov2Api.GetPipelineArtifactUrl();System.out.println(s);}
}

存在的问题

实际有两个API ListPipelineRuns GetPipelineRun调用返回403,直接从调试页面复制下载的代码也不行,估计是换接口了,

http://www.xdnf.cn/news/701191.html

相关文章:

  • C++模板语法大全
  • Rust 的Hello World
  • 在qt中使用c++实现与Twincat3 PLC变量通信
  • 知行之桥如何将消息推送到钉钉群?
  • 前端面经 hook 获取dom元素
  • Cookie与Session简介-笔记
  • 代谢测定试剂盒_生化制剂_Sigma-Aldrich®实验室用品及生产材料
  • FastApi学习
  • AMBA-AHB的控制信号
  • jenkins部署slave动态节点
  • java 开发中 nps的内网穿透 再git 远程访问 以及第三放支付接口本地调试中的作用
  • 使用 find 遍历软链接目录时,为什么必须加 -L
  • 华为OD最新机试真题-按单词下标区间翻转文章内容-OD统一考试(B卷)
  • 【案例95】“小”问题引发的“大”发现---记一次环境修复
  • 十六进制数据转换为对应的字符串
  • Python 如何让自动驾驶的“眼睛”和“大脑”真正融合?——传感器数据融合的关键技术解析
  • Java+POI+EXCEL导出柱形图(多列和单列柱形图)
  • 外骨骼驾驶舱HOMIE——3500元让人形机器人1:1复刻人类动作:类似Mobile ALOHA主从臂的主从分离版
  • 深度学习入门:从零搭建你的第一个神经网络
  • Vue3对接deepseek实现ai对话
  • 系统性学习C语言-第十讲-操作符详讲
  • javascript中运算符的优先级
  • 如何把示例数据0.617、0.229、0.174保留两位小数,并在后面添加%处理,处理后的结果如下:61.7%、22.9%、17.4%
  • Java | 韩顺平 循序渐进学Java自用笔记---OOP高级(二)
  • Kaggle-基于xgboost的销量预测
  • Java基础 Day23
  • ROC和生存曲线的绘制-spss
  • 精准监测,健康无忧--XC3576H工控主板赋能亚健康检测仪
  • 数据库相关面试
  • 74道TypeScript高频题整理(附答案背诵版)