So, I have got a Jenkins job which is a parameterized build. I allow the users to select one of the environments where they want to execute the build. This parameter is stored in variable ${my_env}. Then I use "Execute Windows Batch Command" component in Job's configuration to execute the following command :
setx /M envi %my_env%
This allows me to set the environment variable on my windows slave machine as envi=my_env. Now I have my project on this slave machine which is python based, and I fetch the environment variable in my project using os.environ['envi'] and execute the code further accordingly based on the value of 'envi'. Problem is when I first execute this job, it is all fine. It fetches the correct value of environment variable 'envi' and execute the correct code as per the environment selected. But when I execute it second time choosing the different environment from build parameters, it does not update in my project and it picks the old value of environment variable 'envi'. I have verified that the actual value of environment is updated using the Setx command, but my python project still fetches the old value. Any ideas anyone?