1

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?

1
  • have you tried an environment variable? or script writing out your package.json? Commented Dec 18, 2020 at 19:20

1 Answer 1

2

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",
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. the inline solution is what I was looking for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.