Skip to content

Instantly share code, notes, and snippets.

@lewang
Created March 16, 2016 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewang/9fb727ef664798290d89 to your computer and use it in GitHub Desktop.
Save lewang/9fb727ef664798290d89 to your computer and use it in GitHub Desktop.
var util = require("util");
var request = require('request');
var apiKey = process.env.CIRCLE_KEY;
var org = "circleci";
var project = "circle";
var branch = "master";
function getArtifacts(buildNum) {
var url = util.format("https://circleci.com/api/v1/project/%s/%s/%s/artifacts?circle-token=%s", org, project, buildNum, apiKey);
request({url: url, json: true}, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log("Got a response: ", body);
} else {
console.log("Got an error: ", error, ", status code: ", response.statusCode);
}
});
};
function getLatestSuccessfulArtifacts() {
var url = util.format("https://circleci.com/api/v1/project/%s/%s/tree/%s?shallow=true&filter=successful&limit=1&circle-token=%s", org, project, branch, apiKey);
console.log(url);
request({url: url, json: true}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var buildNum = body[0].build_num;
getArtifacts(buildNum);
} else {
console.log("Got an error: ", error, ", status code: ", response.statusCode);
}
});
};
getLatestSuccessfulArtifacts();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment