Created
March 16, 2016 14:16
-
-
Save lewang/9fb727ef664798290d89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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