jakejs / jake

JavaScript build tool, similar to Make or Rake. Built to work with Node.js.
http://jakejs.com
Apache License 2.0
1.97k stars 190 forks source link

Jake fails to properly use environment variables passed as arguments when value contains equal sign #422

Closed yentlprojects closed 1 year ago

yentlprojects commented 1 year ago

When passing arguments to Jake using the environment variables syntax, it breaks when a value contains an equal sign:

Say we have the following task:

task('test', function () {
    console.log("extra_arg_string:", process.env.extra_arg_string);
});

Which we invoke as follows:

jake test extra_arg_string="-Ddb.username=my-db-user -Ddb.password=my-password"

The process.env variable stops right before the first equals sign in the value:

extra_arg_string: -Ddb.username

Escaping equals sign with backslashes also does not seem to work.

mde commented 1 year ago

This looks like a valid bug, although an easy workaround would be simply to pass two different environment variables, one for Ddb.username and Ddb.password, so this doesn't seem like a really high priority to fix.

yentlprojects commented 1 year ago

In understand this might not be high priority to fix, but in our use case it isn't really possible to just pass 2 environment variables, because this heavily limits the reusability of the script, as this "extra_arg_string" command gets passed through to a maven build inside a docker container. The goal is for the jake script to accept any amount of env vars/system properties and pipe those through to the docker build. (but only those that are meant for the docker build, not potentially other env vars that might be used elsewhere in the jake script)

mde commented 1 year ago

Another possibility would be simply to set env variables before invocation, like so:

EXTRA_ARG_STRING="-Ddb.username=my-db-user -Ddb.password=my-password" jake test`

Another way to set an env variable for your tasks would be to require a file in your jakefile that sets them for you:

process.env.EXTRA_ARG_STRING = 'Ddb.username=my-db-user -Ddb.password=my-password';

That "equals" syntax was originally implemented simply to copy all of Rake's API. There's no specific reason to set environment variables that way.

Hope that helps.

mde commented 1 year ago

I would add, that "equals" syntax actually sets full-blown environment variables. If you're just wanting to pass args through the Jake task, you'd be better served by just passing args:

https://jakejs.com/docs-page.html#item-advanced-usage-passing-parameters