Created
October 2, 2020 01:45
-
-
Save lmgeorge/0465fab2b8e2567d08dfe350ffb05c39 to your computer and use it in GitHub Desktop.
Print environment variables and properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.System | |
import java.util.TreeMap | |
import java.util.Comparator | |
def env = new TreeMap<String, String>(System.getenv()).toSorted(new Comparator<Map.Entry<String, String>>() { | |
@Override | |
int compare(Map.Entry<String, String> entry1, Map.Entry<String, String> entry2) { | |
return entry1.key <=> entry2.key | |
} | |
}) | |
def props = System.getProperties() | |
def names = props.stringPropertyNames() | |
.toSorted(new Comparator<String>() { | |
@Override | |
int compare(String s, String t1) { | |
return s <=> t1 | |
} | |
}) | |
println("Environment Variables:") | |
env.entrySet() | |
.each {entry -> println("\t${entry.key}: ${entry.value}")} | |
println("\n\nProperties:") | |
names.forEach({name -> | |
def value = props.getProperty(name, '[not found]') | |
println("\t${name}: ${value}") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment