Send gruntjs log warnings in TeamCity service message format.
This plugin requires Grunt ~0.4.1
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-teamcity --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-teamcity');
In your project's Gruntfile, add a section named teamcity
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
teamcity: {
options: {
// Task-specific options go here.
},
all: {}
}
})
Type: Boolean
Default value: false
A boolean that when true will suppress the grunt log output - only the TeamCity service message will be sent to the console.
Type: Object
Default value:
{
warning: 'ERROR',
failure: 'FAILURE',
error: 'ERROR'
}
A hash that maps grunt log message types to TeamCity service message statuses. Note that the TeamCity 'WARNING' status does not flag a task as failed.
Default options are normally all you need so no config section is required. Make sure that you include the teamcity as the first task so that the messaging is setup for all subsequent tasks. In this example we run concat as the default task but set the teamcity logging first.
grunt.registerTask('default', ['teamcity', 'concat']);
grunt.initConfig({
teamcity: {
all: {} // need a task even if its an empty one
}
})
As grunt-teamcity is a multitask you need to define at least one subtask, e.g. all
In this example, custom options are used to turn off the normal grunt logs for warning, fail and error. We have also redefined the status hash to report grunt warnings as Teamcity warnings (so they don't cause the task to fail).
grunt.initConfig({
teamcity: {
options: {
suppressGruntLog: true,
status: {
warning: 'WARNING',
failure: 'FAILURE',
error: 'ERROR'
}
}
},
concat: {
//...
}
Teamcity on windows does not flush the stdout stream before exiting the grunt node process. There has been some work around this in both nodejs and grunt, but it is by no means resolved. If you see missing output in your Teamcity build log then try running the grunt task using the the solution documented here on StackOverflow
Seems that by redirecting to a file the output is synchronous, whereas with pipe (or TC plugin execute method) the output is async and not captured before the node process exits. The bat file captures the exit code from grunt and passes it onto Teamcity.
from http://stackoverflow.com/a/23844564/625200
@echo off
:: prepare environment
setlocal enableextensions
set "tempFile=%temp%\%~nx0.%random%.grunt.tmp"
:: run grunt
call grunt default --no-color > "%tempFile%"
:: Keep the grunt exit code
set "exitCode=%ERRORLEVEL%"
:: Print the grunt output
type "%tempFile%"
:: cleanup and exit with adecuated value
del /q "%tempFile%" >nul 2>nul
endlocal & exit /b %exitCode%
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
- Make it a multitask
- Add tests
- Ready for publish to https://npmjs.org
- update readme and contact info
- Ensure TeamCity messages don't get parsed twice
- Add travis CI