node-gradle / node-gradle/gradle-node-plugin

You can't pass dynamic environment to npm run

Open
#242 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.