Last active
July 18, 2021 04:42
-
-
Save andgineer/155a8ef1a4e4e29bd68ee9ef1d47b9ed to your computer and use it in GitHub Desktop.
Load .env file in Jenkins https://sorokin.engineer/posts/en/jenkins_load_env_vars_with_expanding.html
This file contains hidden or 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
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