How can I get System variables to print in gradle?


#1

How will I able to get the system variables to print in gradle? Like the computer name as $user.name and todays date


(Chris Doré) #2

If you are referring to environment variables, then you can access them in the same way as Groovy/Java, using the System class.

For example:

println System.getenv( 'MY_VAR' )

#3

I got username to work. By using println System.getenv USERNAME.
Basically I got to go to system environment and add it.
But I cant get Todays date, build number, release number to work because I don’t know what to fill in for the variable values.


(Chris Doré) #4

Could you describe a bit more about what you are trying to accomplish?


#5

I’m trying to use system var to print out Today’s date.


(Chris Doré) #6

You also mentioned build and release numbers which made me think you were trying to accomplish something CI related (ie Jenkins builds).

You could use instances of the Date class instead of environment variables:

println new Date()

Groovy also offers some enhancements to the Date class. Here are some examples.