Get the build log through the drone rest API
Drone is a cicd tool that provides a rest API. Let's briefly introduce how to use the API to obtain the build log.
Get token
Log in to the drone, click the avatar, and select token in the menu
Just copy the token
API introduction
Drone's APIs fall into several categories
Call example:
Build API
Build list
Get the latest build of the warehouse:
GET /api/repos/{owner}/{repo}/builds
curl -i http://drone.YOUR_HOST.cn/api/repos/jqpeng/springboot-rest-demo/builds -H "Authorization: Bearer TOKEN"
Example of response body:
[
{
"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 details
Obtain the construction details through this interface, return the construction status and other information, {build} is the number in the above list, that is, the construction serial 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 is the construction step. Remember PID, and it is useful to get the construction log
Build log
To get the build log, you need to pass in {log} and {PID}. Log is the above {build} and {PID} is the PID returned in the previous step
GET /api/repos/{owner}/{repo}/logs/{log}/{pid}
Example of response body:
[
{
"proc": "clone","pos": 0,"out": "+ git init\n"
},{
"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.git\n"
},"pos": 3,"out": "+ git fetch --no-tags origin +refs/heads/master:\n"
},"pos": 4,"out": "From https://github.com/octocat/hello-world\n"
},"pos": 5,"out": " * branch master -> FETCH_HEAD\n"
},"pos": 6,"out": " * [new branch] master -> origin/master\n"
},"pos": 7,"out": "+ git reset --hard -q 62126a02ffea3dabd7789e5c5407553490973665\n"
},"pos": 8,"out": "+ git submodule update --init --recursive\n"
}
]