Skip to content

Instantly share code, notes, and snippets.

@andgineer
Last active July 18, 2021 04:42
Show Gist options
  • Save andgineer/155a8ef1a4e4e29bd68ee9ef1d47b9ed to your computer and use it in GitHub Desktop.
Save andgineer/155a8ef1a4e4e29bd68ee9ef1d47b9ed to your computer and use it in GitHub Desktop.
private void loadVarsFromFile(String path) {
def file = readFile(path)
.replaceAll("(?m)^\\s*\\r?\\n", "") // skip empty line
.replaceAll("(?m)^#[^\\n]*\\r?\\n", "") // skip commented lines
file.split('\n').each { envLine ->
def (key, value) = envLine.tokenize('=')
env."${key}" = "${value.trim().replaceAll('^\"|\"$', '')}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment