1

I am using nodejs build step to create enviornment variables (on linux agent) using process.env["something"] = "somethingelse". After creation if I echo the variables, i can see the values but as soon as I go in next build step all the env variables created go away. How can I fix this issue? I am using team city 10. I can not use the env variables functioanlity provided as part of parameters so that is why need to go via this route. Any help will be really appreciated. Here is the code written in nodejs teamcity step.

    fs = require('fs');
    var envFile = process.argv[2];

    fs.readFile(envFile , 'utf8', function(err, data) {
    if (err) {
        return console.log(err);
    }
    var json = JSON.parse(data);

    for (var key in json) {
      process.env[key] = json[key];
      console.log(process.env[key]);
     }
});
Ashish Modi
  • 7,529
  • 2
  • 20
  • 35
  • Can you show what you've already tried? `process.env.something = "SomethingElse"` is only going to affect the in-memory representation of the environment variable in the current process space; if you need it to persist to other processes you'll need to use system tools to update them. – Paul Jun 02 '17 at 14:05
  • `fs = require('fs'); var envFile = process.argv[2]; fs.readFile(envFile , 'utf8', function(err, data) { if (err) { return console.log(err); } var json = JSON.parse(data); for (var key in json) { process.env[key] = json[key]; console.log(process.env[key]); } });` – Ashish Modi Jun 02 '17 at 14:07
  • Update your question, please, it's hard to read that stuff in a comment. – Paul Jun 02 '17 at 14:07
  • updated the original question . – Ashish Modi Jun 02 '17 at 14:29
  • Is there a reason you can't just set the environment variables using for example a .env file, vice doing it in memory? – Paul Jun 02 '17 at 18:42
  • 2
    You can write a structured message to the log to change it, as explained here https://stackoverflow.com/questions/8219493/teamcity-passing-an-id-generated-in-one-build-step-to-a-later-build-step – KeepCalmAndCarryOn Jun 03 '17 at 06:51

0 Answers0