Skip to content

Instantly share code, notes, and snippets.

@natural-affinity
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save natural-affinity/b8b67158f6cdf9a57df8 to your computer and use it in GitHub Desktop.

Select an option

Save natural-affinity/b8b67158f6cdf9a57df8 to your computer and use it in GitHub Desktop.
Trigger a parameterized build via the Jenkins REST API
var request = require('request');
var express = require('express');
var validator = require('validator');

module.exports = (function () {
  'use strict';
  var api = express.Router();

  api.use(function(req, res, next) {
    console.log('api router invoked');
    next();
  });

  api.route('/build/:slug')
    .get(function (req, res, next) {
      var slug = validator.escape(req.params.slug);
      var url = 'http://<host>:<port>/job/<job-name>/buildWithParameters?slug=' + slug;

      request({url: url}, function (err, response, body) {
        if (err) 
          res.status(500).end();
        else
          res.status(200).end();
      });
    });

  return api;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment