Skip to content

Instantly share code, notes, and snippets.

@omercs
Created February 25, 2014 22:39
Show Gist options
  • Save omercs/9219482 to your computer and use it in GitHub Desktop.
Save omercs/9219482 to your computer and use it in GitHub Desktop.
Travis CI is open source continuous integration for many languages. It sometimes fails if it does not open emulator or similar. It has API to trigger builds and do some queries. Following example shows how to trigger last build, if it has an error. You can run this script as a scheduled task.
To run this:
Install node.js first
Npm install travis-ci
Node trigger_for_me.js
Put this into trigger_for_me.js
var Travis = require('travis-ci');
var travis = new Travis({
version: '2.0.0'
});
var TOKEN = "xxxyourGithubTokenxxx";
retryFailedLastJob('azure-activedirectory-library-for-android');
retryFailedLastJob('azure-activedirectory-library-for-ios');
function retryFailedLastJob(repo_name) {
var datenow = new Date();
console.info("Date: " + datenow);
console.info("You are running test scheduled job for " + repo_name);
travis.auth.github({
github_token: TOKEN
}, function (err, res) {
// res => {
// access_token: XXXXXXX
// }
console.info("Received response for github token");
travis.authenticate({
access_token: res.access_token
}, function (err) {
// we've authenticated!
console.info("It is authenticated");
travis.repos({
owner_name: 'MSOpenTech',
name: repo_name
}, function (err, res) {
if (err) {
console.error("travis.repos err:" + err);
} else {
var repo = res.repo;
console.info("repos:" + repo + " res:" + res + " buildId:" + repo.last_build_id + " number:" + repo.last_build_number + " state:" + repo.last_build_state + " started_at:" + repo.last_build_started_at + " finished_at:" + repo.last_build_finished_at);
var build_id = repo.last_build_id;
if (repo.last_build_state === "errored") {
console.info("Errored build");
repoBuild(build_id);
}
}
});
});
});
}
function repoBuild(build_id) {
console.info("repoBuild is called for build_id:" + build_id);
travis.requests({
build_id: build_id
}, function (err, res) {
if (err) {
console.info("err:" + err);
} else {
console.info("result:" + res.result);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment