node-gradle / node-gradle/gradle-node-plugin
You can't pass dynamic environment to npm run
Nobody has claimed this yet.
- Dominant language
- Groovy
- Stars
- 677
- Forks
- 120
- PR merge metrics
- No merged PRs in 30d
Description
I know I can add environment variables like this:
task verify(type: NpmTask) {
environment = ['CYPRESS_BASE_URL' : "http://localhost:9999"]
args = ['run', 'verify']
}
But in my case the environment variable is only set later on from a custom plugin called "backendServer".
So I tried to add environment in doFirst:
verify.doFirst {
def randomPort = backendServer.getLocalPort()
environment = ['CYPRESS_BASE_URL' : "http://localhost:" + randomPort]
}
But this does not work as environment is immutable.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the verify NpmTask and its doFirst action as the entry points, and trace how the task's environment is handled when npm run executes. Reproduce the backendServer-generated port scenario and determine how a value assigned later can reach the npm process; done means CYPRESS_BASE_URL uses that runtime port.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, nodejs
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100