grunt-run
grunt-run copied to clipboard
Support for environment variables
Requesting support for environment variables when defining a target as shown below:
grunt.initConfig({
run: {
options: {
// Task-specific options go here.
},
your_target: {
cmd: 'executable',
env:{
'NODE_ENV': 'production'
},
args: [
'arg1',
'arg2'
]
}
}
})
This might be not relevant to the issue creator at this point in time, but I just lost a considerable amount of time through the fact that this feature is so thoroughly documented. So here is what I found:
This feature was initially implemented in #7 and first shipped with v0.3.0
.
Take care though:
- You need to specify variables as
options.env
, so differently nested thanargs
, which was quite unexpected for me. - The environment variables specified here are passed directly to
child_process.spawn
asopts.env
. If these are customized, they are overwritten and not merged with the variables of the calling process, what means that e.g. PATH would be missing and e.g.node
eventually not found.
So you might need to specify something like:
grunt.initConfig({
run: {
my_task: {
options: {
env: Object.assign({}, process.env, {
'NODE_ENV': 'production',
}),
},
},
args: [
'arg1',
'arg2'
],
},
},
});