Forum Discussion

oleksii's avatar
oleksii
Occasional Contributor
9 years ago

How to set OS environment variable from groovy script.

I've not found a way to set OS environment variable from a groovy test step. Tried this:

System.setProperty("prp_name", "value")

def prp = System.getProperties()
log.info prp["prp_name"]

It only works within SoapUI, but when I check if such variable exists in CMD it does not return anything:

c:\>set prp_name
Environment variable prp_name not defined

 

  • nmrao's avatar
    nmrao
    Champion Level 3
    If you need that property to be available on command prompt, you need to set either in the current terminal or in system environment variable.
  • KarelHusa's avatar
    KarelHusa
    Champion Level 1

    If you set an environment (operating system) variable in a process, it will exist in that process and its child processes.

     

    You can check that -- launch two cmd prompts and set a variabe in one of them. You won't be able to reach it in the other. But if you launch a child terminal, it will have the variable.

     

    If you execute a process from within SoapUI, it will be a child process and thus will have the variable.