Returning a value from Jenkins job

Let’s say we have a Jenkins pipeline job, that creates a virtual machine and installs a service on it.
We will create 3 jobs — one takes a machine name and a service name as a parameter and calls a second job — to create a machine and a third job to install a service.
The third job need the machine IP to install a service, so the second job, which creates the virtual machine needs to return the machine IP.
Recently I discovered that it is possible using environment variables. After downstream job finished, we can access its variables by
b.getBuildVariables()
Jenkins file of the first, “main” job:
Jenkins file of the second, “create vm” job:
So this way we can return any number of values from downstream Jenkins job and use it in the next job in the chain!
Enjoy!