加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

通过 Drone Rest API 获取构建记录日志

发布时间:2020-12-15 06:41:33 所属栏目:Java 来源:网络整理
导读:Drone是一款CICD工具,提供rest API,简单介绍下如何使用API 获取构建日志。 获取token 登录进入drone,点头像,在菜单里选择token 复制token即可 API 介绍 Drone的api分为几大类 Builds 构建 Cron 定时任务 Repos 仓库 Secrets User 用户 Users 调用举例:

Drone是一款CICD工具,提供rest API,简单介绍下如何使用API 获取构建日志。

获取token

登录进入drone,点头像,在菜单里选择token

enter description here

复制token即可

API 介绍

Drone的api分为几大类

  • Builds 构建
  • Cron 定时任务
  • Repos 仓库
  • Secrets
  • User 用户
  • Users

调用举例:

enter description here

Build API

构建列表(Build List)

获取仓库的最新构建:

GET /api/repos/{owner}/{repo}/builds

curl -i http://drone.YOUR_HOST.cn/api/repos/jqpeng/springboot-rest-demo/builds -H "Authorization: Bearer TOKEN"

响应正文示例:

[
  {
      "id": 100207,"repo_id": 296163,"number": 42,"status": "success","event": "pull_request","action": "sync","link": "https://github.com/octoat/hello-world/compare/e3320539a4c0...9fc1ad6ebf12","message": "updated README","before": "e3320539a4c03ccfda992641646deb67d8bf98f3","after": "9fc1ad6ebf12462f3f9773003e26b4c6f54a772e","ref": "refs/heads/master","source_repo": "spaceghost/hello-world","source": "develop","target": "master","author_login": "octocat","author_name": "The Octocat","author_email": "octocat@github.com","author_avatar": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c","sender": "bradrydzewski","started": 1564085874,"finished": 1564086343,"created": 1564085874,"updated": 1564085874,"version": 3
  }
]

构建详情

通过该接口获取构建详情,返回构建状态等信息,{build} 为上面列表里的number,既构建序号。

GET /api/repos/{owner}/{repo}/builds/{build}

Example Response Body:

{
    "id": 39862,"number": 20,"parent": 0,"event": "push","error": "","enqueued_at": 1576636849,"created_at": 1576636849,"started_at": 1576636850,"finished_at": 1576639053,"deploy_to": "","commit": "7729006bfe11933da6c564101acaf8c7f78c5f62","branch": "master","refspec": "","remote": "","title": "","message": "通过update更新n","timestamp": 0,"sender": "","author": "jqpeng","author_avatar": "https://www.gravatar.com/avatar/4ab53b564545f18efc4079c30a2d35cf.jpg?s=128","author_email": "jqpeng@iflytek.com","link_url": "","signed": false,"verified": true,"reviewed_by": "","reviewed_at": 0,"procs": [
        {
            "id": 247912,"build_id": 39862,"pid": 1,"ppid": 0,"pgid": 1,"name": "","state": "success","exit_code": 0,"start_time": 1576636850,"end_time": 1576639053,"machine": "21e73ce43038","children": [
                {
                    "id": 247913,"pid": 2,"ppid": 1,"pgid": 2,"name": "clone","start_time": 1576636853,"end_time": 1576636933,"machine": "21e73ce43038"
},{
                    "id": 247914,"pid": 3,"pgid": 3,"name": "build","start_time": 1576636933,"end_time": 1576636998,"machine": "21e73ce43038"
}
]
}
]
}

procs 是构建的步骤,记住pid,获取构建日志有用

构建日志

获取构建日志,需要传入{log} 和 {pid},log是上面的{build},{pid}是上一步返回的pid

GET /api/repos/{owner}/{repo}/logs/{log}/{pid}

响应正文示例:

[
  {
    "proc": "clone","pos": 0,"out": "+ git initn"
  },{
    "proc": "clone","pos": 1,"out": "Initialized empty Git repository in /drone/src/github.com/octocat/hello-world/.git/n"
  },"pos": 2,"out": "+ git remote add origin https://github.com/octocat/hello-world.gitn"
  },"pos": 3,"out": "+ git fetch --no-tags origin +refs/heads/master:n"
  },"pos": 4,"out": "From https://github.com/octocat/hello-worldn"
  },"pos": 5,"out": " * branch            master     -> FETCH_HEADn"
  },"pos": 6,"out": " * [new branch]      master     -> origin/mastern"
  },"pos": 7,"out": "+ git reset --hard -q 62126a02ffea3dabd7789e5c5407553490973665n"
  },"pos": 8,"out": "+ git submodule update --init --recursiven"
  }
]

作者:Jadepeng
出处:jqpeng的技术记事本--http://www.cnblogs.com/xiaoqi
您的支持是对博主最大的鼓励,感谢您的认真阅读。
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读