mbt icon indicating copy to clipboard operation
mbt copied to clipboard

Passing command line arguments to `build` or any command

Open coulson84 opened this issue 5 years ago • 5 comments

Is it possible to pass command line arguments when calling mbt build or mbt run-in

I am looking to use mbt for but currently we would call, for example, npm run dev:eap -- --DEV_API <custom host domain> or to pass arguments in during a build that configure how the build executes. Is there any way to do this with mbt I couldn't see anything in the documentation that indicated it was possible?

coulson84 avatar Apr 11 '19 16:04 coulson84

Custom arguments are specified in .mbt.yml. In this instance (assuming this is your build command in linux), you could do something like:

build:
  linux:
    cmd: npm
    args: ['run', 'dev:eap', '--', '--DEV_API', <custom host domain>]

hth

buddhike avatar Apr 11 '19 21:04 buddhike

Schema of .mbt.yml is documented here: https://mbtproject.github.io/mbt/#synopsis

buddhike avatar Apr 11 '19 21:04 buddhike

I understand that but the <custom host domain> will change according to the stage we are building - for development it is one thing, testing it is different and so on. Is there a way to have the <custom host domain> value, in the args array, change according to values passed in from the command line?

coulson84 avatar Apr 12 '19 09:04 coulson84

Sorry I misunderstood your question 😊.

Currently this is supported via environment variables. To achieve this, you would need a script like this:

#!/bin/sh

set -e
npm run dev:eap -- --DEV_API $DEV_API

Then you configure that as your command in .mbt.yml and at the point you invoke build, you do so with the correct environment values.

DEV_API="https://dev-api/" mbt build

As a side note, it would be really nice to have a feature to expand arguments to a command with environment variables so that you would not have to write the wrapper script 😉

buddhike avatar Apr 12 '19 11:04 buddhike

Yeah - this is the approach I thought I would have to take (but hoped I could avoid). Thanks for the response. Would like to offer my help developing this as a feature but don't have much free time at the moment 😞

coulson84 avatar Apr 12 '19 13:04 coulson84