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

news2025/6/3 6:20:47

参考文档:

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-hangzhou
    public 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错误403
    public 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 获取流水线单个运行示例详情 -->403
    public 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;
    }

    //获取流水线制品URL
    public 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-hangzhou
    public 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错误403
    public 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 获取流水线单个运行示例详情 -->403
    public 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;
    }


    //获取流水线制品URL
    public 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); // 替换为你的 Secret

        config.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,直接从调试页面复制下载的代码也不行,估计是换接口了。

问题处理:通过给阿里云提工单发现,需要在云效的管理后台将这个RAM用户的角色从成员改成管理员才能调通。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2395138.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

​​知识图谱:重构认知的智能革命​

在数字经济的浪潮中&#xff0c;知识图谱正悄然掀起一场认知革命。它不仅是技术的迭代&#xff0c;更是人类从“数据依赖”迈向“知识驱动”的里程碑。当谷歌用知识图谱优化搜索引擎、银行用它穿透复杂的金融欺诈网络、医院用它辅助癌症诊疗时&#xff0c;这项技术已悄然渗透到…

【计算机网络】4网络层①

这篇笔记讲IPv4和IPv6。 为了解决“IP地址耗尽”问题,有三种措施: ①CIDR(延长IPv4使用寿命) ②NAT(延长IPv4使用寿命) ③IPv6(从根本上解决IP地址耗尽问题) IPv6 在考研中考查频率较低,但需掌握基础概念以防冷门考点,重点结合数据报格式和与 IPv4 的对比记忆。…

MATLAB中的table数据类型:高效数据管理的利器

MATLAB中的table数据类型&#xff1a;高效数据管理的利器 什么是table数据类型&#xff1f; MATLAB中的table是一种用于存储列向数据的数据类型&#xff0c;它将不同类型的数据组织在一个表格结构中&#xff0c;类似于电子表格或数据库表。自R2013b版本引入以来&#xff0c;t…

Dropout 在大语言模型中的应用:以 GPT 和 BERT 为例

引言 大型语言模型&#xff08;LLMs&#xff09;如 GPT&#xff08;生成式预训练 Transformer&#xff09;和 BERT&#xff08;双向编码器表示 Transformer&#xff09;通过其强大的语言理解和生成能力&#xff0c;彻底改变了自然语言处理&#xff08;NLP&#xff09;领域。然…

gitLab 切换中文模式

点击【头像】--选择settings 选择【language】,选择中文&#xff0c;点击【保存】即可。

133.在 Vue3 中使用 OpenLayers 实现画多边形、任意编辑、遮罩与剪切处理功能

&#x1f3ac; 效果演示截图&#xff08;先睹为快&#xff09; ✨ 功能概览&#xff1a; ✅ 鼠标画任意形状多边形&#xff1b; ✏️ 点击“修改边界”可拖动顶点&#xff1b; &#x1f7e5; 点击“遮罩”后地图除多边形区域外变红&#xff1b; ✂️ 点击“剪切”后仅显示选…

4.8.4 利用Spark SQL实现分组排行榜

在本次实战中&#xff0c;我们的目标是利用Spark SQL实现分组排行榜&#xff0c;特别是计算每个学生分数最高的前3个成绩。任务的原始数据由一组学生成绩组成&#xff0c;每个学生可能有多个成绩记录。我们首先将这些数据读入Spark DataFrame&#xff0c;然后按学生姓名分组&am…

【五子棋在线对战】一.前置知识的了解

前置知识的了解 前言1.Websocketpp1.1 使用Websocketpp的原因1.2 Websocket常用接口1.3 Websocket搭建服务器流程 2.JsonCpp2.1 Json 数据对象类的表示2.2序列化和反序列化的接口2.3 演示代码 3.Mysql![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/93305f423b544fc1…

历年中国科学技术大学计算机保研上机真题

2025中国科学技术大学计算机保研上机真题 2024中国科学技术大学计算机保研上机真题 2023中国科学技术大学计算机保研上机真题 在线测评链接&#xff1a;https://pgcode.cn/school?classification1 拆分数字 题目描述 给定一个数字&#xff0c;拆分成若干个数字之和&#xff…

HackMyVM-Art

信息搜集 主机发现 ┌──(kali㉿kali)-[~] └─$ nmap -sn 192.168.43.0/24 Starting Nmap 7.95 ( https://nmap.org ) at 2025-05-31 03:00 EDT Nmap scan report for 192.168.43.1 Host is up (0.0047s latency). MAC Address: C6:45:66:05:91:88 (Unknown) Nmap scan rep…

网页前端开发(基础进阶1)

颜色表示方法3种&#xff1a; 1.关键字&#xff1a; color&#xff1a;green&#xff1b; gray red yellow 2.rgb表示法&#xff1a;红&#xff0c;绿&#xff0c;蓝三原色。rgb&#xff08;r&#xff0c;g&#xff0c;b&#xff09;&#xff0c;r表示红色&#xff0c;g表示绿…

如何找到一条适合自己企业的发展之路?

一个创业型的企业&#xff0c;开始就需要面向市场&#xff0c;通过自己的服务或产品&#xff0c;帮助用户解决问题&#xff0c;为客户创造价值&#xff0c;通过为客户创造的价值&#xff0c;出创造一定的的现金流&#xff0c;让企业存活下来&#xff01; 企业的运营过程中&…

Vue-数据监听

数据监听 基础信息 代码 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><title>数据监听</title><!-- 引入Vue --><script type"text/javascript" src"../js/vue.js&qu…

当前用户的Git全局配置情况:git config --global --list

通过config命令可以查询当前用户的全局配置情况。这些配置项定义了 Git 在全局范围内的行为&#xff0c;包括如何处理大文件、SSL 证书验证以及提交时的用户信息。 git config --global --list http.sslVerifyfalse 这个配置项禁用了 SSL 证书验证。这在与自签名证书的 Git 服…

AI生态警报:MCP协议风险与应对指南(中)——MCP Server运行时安全​​

作为连接AI模型与外部工具的“USB-C接口”&#xff0c;MCP协议成为AI生态的核心枢纽&#xff0c;其安全风险已从理论威胁转化为实际攻击目标。 AI生态警报&#xff1a;MCP协议风险与应对指南&#xff08;上&#xff09;——架构与供应链风险https://blog.csdn.net/WangsuSecur…

day15 leetcode-hot100-29(链表8)

19. 删除链表的倒数第 N 个结点 - 力扣&#xff08;LeetCode&#xff09; 1.暴力法 思路 &#xff08;1&#xff09;先获取链表的长度L &#xff08;2&#xff09;然后再次遍历链表到L-n的位置&#xff0c;直接让该指针的节点指向下下一个即可。 2.哈希表 思路 &#xff0…

MonitorSDK_性能监控(从Web Vital性能指标、PerformanceObserver API和具体代码实现)

性能监控 性能指标 在实现性能监控前&#xff0c;先了解Web Vitals涉及的常见的性能指标 Web Vitals 是由 Google 推出的网页用户体验衡量指标体系&#xff0c;旨在帮助开发者量化和优化网页在实际用户终端上的性能体验。Web Vitals 强调“以用户为中心”的度量&#xff0c;而不…

LeeCode 98. 验证二叉搜索树

给你一个二叉树的根节点 root &#xff0c;判断其是否是一个有效的二叉搜索树。 有效 二叉搜索树定义如下&#xff1a; 节点的左子树只包含 小于 当前节点的数。节点的右子树只包含 大于 当前节点的数。所有左子树和右子树自身必须也是二叉搜索树。 提示&#xff1a; 树中节…

JVM类加载高阶实战:从双亲委派到弹性架构的设计进化

前言 作为Java开发者&#xff0c;我们都知道JVM的类加载机制遵循"双亲委派"原则。但在实际开发中&#xff0c;特别是在金融支付、插件化架构等场景下&#xff0c;严格遵循这个原则反而会成为系统扩展的桎梏。本文将带你深入理解双亲委派机制的本质&#xff0c;并分享…

threejsPBR材质与纹理贴图

1. PBR材质简介 本节课没有具体的代码&#xff0c;就是给大家科普一下PBR材质&#xff0c;所谓PBR就是&#xff0c;基于物理的渲染(physically-based rendering)。 Three.js提供了两个PBR材质相关的APIMeshStandardMaterial和MeshPhysicalMaterial,MeshPhysicalMaterial是Mes…