diff --git a/README.md b/README.md index 4a3ac75..27f68a9 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ npm install jenkins-badge -V, --version output the version number -u, --url Jenkins url (http://user@password:url:port) -p, --port [port] Port (default 2323) + --no-strict Use non-strict SSL ``` Then you can include this type of markdown in your page: diff --git a/bin/jenkins-badge b/bin/jenkins-badge index bed4523..9186bcc 100755 --- a/bin/jenkins-badge +++ b/bin/jenkins-badge @@ -6,6 +6,7 @@ var express = require('express'); var async = require('async'); var program = require('commander'); var pkg = require('../package.json'); +var debug = require('debug')('jenkins-badge'); /** * Parse argv. @@ -15,6 +16,7 @@ program .version(pkg.version) .option('-u, --url ', 'Jenkins url (http://user@password:url:port) ') .option('-p, --port [port]', 'Port (default 2323)', 2323) + .option('--no-strict', 'Use non-strict SSL') .parse(process.argv); if (! program.url) program.help(); @@ -28,9 +30,14 @@ if (! program.url) program.help(); */ function queryLastBuild(name, branch, cb) { + var url = program.url + '/job/' + name + '/lastBuild/git/api/json'; + + debug('GET %s', url); + request.get({ - url: program.url + '/job/' + name + '/lastBuild/git/api/json', - json: true + url: url, + json: true, + strictSSL: program.strict }, function (err, res) { if (err) return cb(err); cb(null, _.find(res.body.buildsByBranchName, function (value, name) { @@ -48,9 +55,14 @@ function queryLastBuild(name, branch, cb) { */ function queryBuild(name, number, cb) { + var url = program.url + '/job/' + name + '/' + number + '/api/json'; + + debug('GET %s', url); + request.get({ - url: program.url + '/job/' + name + '/' + number + '/api/json', - json: true + url: url, + json: true, + strictSSL: program.strict }, function (err, res) { if (err) return cb(err); cb(null, res.body); @@ -89,7 +101,10 @@ var app = express(); app.get('/:name', function (req, res) { getBuild(req.params.name, req.query.branch || 'master', function (err, build) { - if (err) return res.redirect('http://img.shields.io/badge/jenkins-error-lightgrey.svg'); + if (err) { + debug('ERROR', err); + return res.redirect('http://img.shields.io/badge/jenkins-error-lightgrey.svg'); + } if (! build) return res.redirect('http://img.shields.io/badge/jenkins-unknown-lightgrey.svg'); var status = build.result === 'SUCCESS' ? 'passing' : 'failing'; var color = build.result === 'SUCCESS' ? 'brightgreen' : 'red'; diff --git a/package.json b/package.json index c7c5c83..be202d9 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "dependencies": { "async": "^0.9.0", "commander": "^2.2.0", + "debug": "^1.0.4", "express": "^4.5.1", "lodash": "^2.4.1", "request": "^2.37.0"