问题
Every time I close the powershell session or window all the variable created in there is destroyed. Is there any command or way to create a variable which does not gets destoryed evenafter the session is closed. I know using script works but my situation is that my jenkins stage opens one window and creates a variable and the stage is closed which closes the session and in the next stage the new session is opened but all the initial variables are lost. I tried using jenkins environment variable but even though it is updated inside the powershell script but in next session it again gets same variable back.
回答1:
As an example Session 1 our variable is set to a value of 1.
$a = 1
$a | export-clixml -path c:\temp\a.xml
now close the session then run this code after you relaunch Powershell or a newly started session.
if(test-path c:\temp\a.xml)
{
$a = import-clixml -Path c:\temp\a.xml
}
$a
1
来源:https://stackoverflow.com/questions/56637777/how-to-pass-powershell-variable-from-one-session-to-another-or-from-one-stage-to