Skip to content

Instantly share code, notes, and snippets.

@lmgeorge
Created October 2, 2020 01:45
Show Gist options
  • Save lmgeorge/0465fab2b8e2567d08dfe350ffb05c39 to your computer and use it in GitHub Desktop.
Save lmgeorge/0465fab2b8e2567d08dfe350ffb05c39 to your computer and use it in GitHub Desktop.
Print environment variables and properties
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