When you spawn a process, it inherits a copy of environmental variables from the parent. When you chance an environment variable, it only affects that spawned process, it does not propagate back up to the parent (or other children). Even if you explicitly set the variable as global, it will not take effect until the process is restarted.
For the benefit of "clean environment", Jenkins spawns a child process from itself, for every build. This way, when the build is finished, the child process is discarded, and your OS environment is not polluted.
- ENVIRONMENT (global variables) | ------ Jenkins process (copy of ENVIRONMENT variables) | | | ----- Build 1 (copy of Jenkins process variables) | | | | | ------ %RESULT% variable changed | | | ----- Build 2 (copy of Jenkins process variables) | ------ Other process (copy of ENVIRONMENT variables)
If your Build 1 changes any environment variable, it does not affect Build 2 or other OS processes that are running.
Even if you use SETX command to force the variable to be propagated back to global ENVIRONMENT, your Jenkins process will not pick it up, unless restarted, and neither will Jenkins child build processes, since they get a copy of Jenkins process.
Workaround
Use EnvInject plugin.
At the end of your job, write the variable you want into a properties file.
echo result=%result% > myvars.props
This file should list, line by line, key-value pairs of variables and their values.
In the next build, you can use EnvInject plugin to read the properties file, and inject these variables into the spawned process. From that point, you can use %result% as any other global environment variable.
Jenkins parameter? Please explain in more details. You can see thatset /P RESULT= < temp.txtwill give youecho %RESULT%.