In this post I describe Node.js support plugin that was implemented in Kotlin
Node.js
The goal of the plugin is to provide an initial support for Node.js scripts execution on TeamCity. Plugin does the following:
- Detects system installed Node.js on the agent machine, it adds node.js configuration parameter with Node.js version
- Provides a build runner to start .js file or script text
This is the runner settings page. Here you can provide script of .js file, script arguments and Node.js additional arguments (aka options)
Kotlin
In the plugin I decided to use Kotlin. I compile the plugin to Java 1.6
TeamCity requires plugin to extend some Java classes or interfaces and register implementations in Spring Framework Dependency Injection. Classes that I implement with Kotlin are usable as Spring Beans without any extra tricks
In the build runner implementation I had to handle several IO errors. For each error I needed to provide specific error message. This code in Java requires to have many mostly similar try/catch blocks. With Kotlin I solved it nicer, I declared the following function that takes base message and function body:
This function accepts another function to execute. It wraps execution with try/catch to re-throw the error adding details as another exception
The runner code now turned out to be easy to read and simple:
You may read more about Kotlin here
Download
TeamCide.Node plugin source code is found On GitHub. You may also checkout releases branch to download plugin binaries
If you see plugin is missing something, please feel free to post an issue or patch request
Plugin is compiled with TeamCity 7.1 and may work with TeamCity 7.0
To install plugin, simply put downloaded plugin .zip file into <TeamCity Data Directory>/plugins folder and restart TeamCity Server. For more details, there is documentation
comments powered by Disqus