Is there a way to configure a sequence of tasks so that specific subsequent ones (I don't want --force on the whole batch) run even if one fails? For example, consider a case like this
I can do this:
grunt.registerTask('testTheTemp', ['makeTempFiles', 'qunit', 'removeTempFiles']);
But if qunit fails then the removeTempFiles task never runs.
Tasks are grunt's bread and butter. The stuff you do most often, like jshint or nodeunit . Every time Grunt is run, you specify one or more tasks to run, which tells Grunt what you'd like it to do. If you don't specify a task, but a task named "default" has been defined, that task will run (unsurprisingly) by default.
When a task is run, Grunt looks for its configuration under a property of the same name. Multi-tasks can have multiple configurations, defined using arbitrarily named "targets." In the example below, the concat task has foo and bar targets, while the uglify task only has a bar target.
Grunt can perform repetitive tasks very easily, such as compilation, unit testing, minifying files, running tests, etc. Grunt includes built-in tasks that extend the functionality of your plugins and scripts. The ecosystem of Grunt is huge; you can automate anything with very less effort.
Here's one workaround. It's not pretty, but it does solve the issue.
You create two extra tasks which you can wrap at the beginning/end of any sequence that you want to continue even over failure. The check for existing value of grunt.option('force')
is so that you do not overwrite any --force
passed from the command line.
grunt.registerTask('usetheforce_on', 'force the force option on if needed', function() { if ( !grunt.option( 'force' ) ) { grunt.config.set('usetheforce_set', true); grunt.option( 'force', true ); } }); grunt.registerTask('usetheforce_restore', 'turn force option off if we have previously set it', function() { if ( grunt.config.get('usetheforce_set') ) { grunt.option( 'force', false ); } }); grunt.registerTask( 'myspecialsequence', [ 'usetheforce_on', 'task_that_might_fail_and_we_do_not_care', 'another_task', 'usetheforce_restore', 'qunit', 'task_that_should_not_run_after_failed_unit_tests' ] );
I've also submitted a feature request for Grunt to support this natively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With