Last active
June 18, 2018 08:43
-
-
Save stigi/336fa01310d4dbeaecfde1dc24c52e71 to your computer and use it in GitHub Desktop.
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
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