Jeremy Thomas
Jeremy Thomas

Reputation: 6684

Execute bash script within package.json

I am trying to run an NPM script that relies on a variable that needs to be assigned at runtime.

package.json

{
  "version": "4.0.10",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "set-version": "VERSION=(sentry-cli releases propose-version)",
    "release": "sentry-cli releases new -p internal-app $VERSION --finalize",
    ...
  }
}

I've attempted to set the variable in the set-version script however once I run release, the variable is not known.

How can I set this up so that when I run npm run release the variable $VERSION is known?

Upvotes: 1

Views: 1802

Answers (1)

Trott
Trott

Reputation: 70075

Set the environment variable and run the command all at once:

    "release": "VERSION=(sentry-cli releases propose-version) sentry-cli releases new -p internal-app $VERSION --finalize",

If only your command line is using $VERSION you can inline it:

    "release": "sentry-cli releases new -p internal-app `sentry-cli releases propose-version` --finalize",

Upvotes: 2

Related Questions