Automating coffeescript compilation with Jenkins

Problem

I've set up a jenkins CI server on a windows box for one of my projects. There is a portion of it written in Coffeescript. Previously this part wasn't looped into the build process. Now It needs to be.

I haven't seen any coffeescript plugins for jenkins, or much from google on the topic of building coffeescript in jenkins.

I am looking for the simplest way to set up a jenkins build to include a coffee compilation step. Preferably through plugins on jenkins rather then manually installing programs on the box.

Currently the coffeescript is compiled via commands like so

coffee --lint --watch --output "C:\repositories\martha\trunk\bb\app\bin\js/" --compile "C:/repositories/martha/trunk/bb/app/src/"

in the Node.js command prompt on developing boxes

I've also noticed that Jenkins has a node.js plugin where you are capable of running scripts in a build step. I don't believe I can use the commands npm install -g coffee-script or coffee --compile through node.js scripts rather then the command line. Though I hope I am wrong.

Currently the best option I see is to install node.js on the box, use npm to install coffee script, and then run batch scripts as a build step. Though I am willing to pursue this, I would like less manual installation on the box, to ease the use of coffee-script in more projects.

Is this my best option?

Worth saying though I use node.js to compile coffee-script, node.js itself, and its capabilities, are very new to me.

Problem courtesy of: Mike McFarland

Solution

One possible solution is to run the compiler with the script provided in extras/coffee-script.js. You have to use JDK 7 or the latest Rhino (JDK 6 will not work). Here is a link to a simple CoffeeScript compiler in Java

Solution courtesy of: jdb

Discussion

i would recommend

a) installing nodejs plugin + grunt on jenkins -> Jenkins integration with Grunt

b) voting up the excellent instructions :)

c) then using grunt to compile the coffee script, this also means you can easily locally compile coffee script too!!

grunt instructions -> http://gruntjs.com/

grunt coffee script instructions -> https://github.com/gruntjs/grunt-contrib-coffee

basically you need a Gruntfile.js a bit like this

module.exports = function(grunt) {
    // Project configuration.
    grunt.initConfig({
        pkg : grunt.file.readJSON('package.json'),
        coffee: {
            compile: {
                files: {
                    'path/to/result.js': 'path/to/source.coffee', // 1:1 compile
                    'path/to/another.js': ['path/to/sources/*.coffee', 'path/to/more/*.coffee'] // compile and concat into single file
                }
            }
        }
    });
    grunt.loadNpmTasks('grunt-contrib-coffee');
    grunt.registerTask('default', ['grunt-contrib-coffee']);
};

then for the jenkins shell task you just need this, to run grunt and hence coffee script

npm update
grunt
Discussion courtesy of: aqm

This recipe can be found in it's original form on Stack Over Flow.