Skip to content

Instantly share code, notes, and snippets.

@stigi
Last active June 18, 2018 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stigi/336fa01310d4dbeaecfde1dc24c52e71 to your computer and use it in GitHub Desktop.
Save stigi/336fa01310d4dbeaecfde1dc24c52e71 to your computer and use it in GitHub Desktop.
def fetchPassword(identifier) {
if (!Os.isFamily(Os.FAMILY_MAC)) {
println "Not on macOS, falling back to using keystore password from Environment"
return props.getProperty(identifier)
}
def keychainLabel = "${identifier}"
println "Fetching keychain password with label '${keychainLabel}"
def stdout = new ByteArrayOutputStream()
def stderr = new ByteArrayOutputStream()
def keychainExec = exec {
commandLine 'security', '-q', 'find-generic-password', '-gl', "${keychainLabel}"
standardOutput = stdout
errorOutput = stderr
ignoreExitValue true
}
if (keychainExec.exitValue != 0) {
println stdout.toString()
println stderr.toString()
return
}
(stderr.toString().trim() =~ /password: "(.*)"/)[0][1]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment