Send grunt log warnings in TeamCity service message format.
Send gruntjs log warnings in TeamCity service message format.
This plugin requires Grunt
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
In your project's Gruntfile, add a section named
teamcity to the data object passed into
A boolean that when true will suppress the grunt log output - only the TeamCity service message will be sent to the console.
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.
As grunt-teamcity is a multitask you need to define at least one subtask, e.g.
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).
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.
@echo off:: prepare environmentsetlocal enableextensionsset "tempFile=%temp%\%~nx0.%random%.grunt.tmp":: run gruntcall grunt default --no-color > "%tempFile%":: Keep the grunt exit codeset "exitCode=%ERRORLEVEL%":: Print the grunt outputtype "%tempFile%":: cleanup and exit with adecuated valuedel /q "%tempFile%" >nul 2>nulendlocal & 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.