Last active
May 21, 2020 15:30
-
-
Save abdennour/873aaf5599a96cc88599cea7f008e89a to your computer and use it in GitHub Desktop.
Jenkins steps for vault
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
#!/usr/bin/env groovy | |
def call(body){ | |
def config = [:] | |
body.resolveStrategy = Closure.DELEGATE_FIRST | |
body.delegate = config | |
body() | |
def splited = config.secretPath.split('@') | |
def chartPath = config.chartPath | |
def secretPath = splited[0] | |
def key = splited.size() == 2 ? splited[1] : 'value' | |
def saveFile = config.saveFile ?: key == 'value' ? secretPath : "${secretPath}/${key}" | |
WithVaultCredentials { | |
sh """ | |
vault kv get --field=${key} "${config.vaultNamespace}${secretPath}" > "${chartPath}/${saveFile}" | |
""" | |
} | |
} |
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
ReadVaultSecret { | |
vaultNamespace = "secret/devops/${currentEnv}/" | |
chartPath = currentPath | |
secretPath = "kubeconfig" | |
} | |
WriteVaultSecret { | |
secretPath = "secret/projects/helm/${project}/${currentEnv}/${currentApp}-${currentEnv}/${it.key}" | |
value = it.value | |
} |
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
#!/usr/bin/env groovy | |
def call(body){ | |
withCredentials([ | |
string(credentialsId: 'VAULT_ADDR', variable: 'VAULT_ADDR'), | |
string(credentialsId: 'VAULT_TOKEN', variable: 'VAULT_TOKEN')]) { | |
body() | |
} | |
} |
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
#!/usr/bin/env groovy | |
def call(body){ | |
def config = [:] | |
body.resolveStrategy = Closure.DELEGATE_FIRST | |
body.delegate = config | |
body() | |
def key = config.key ?: 'value' | |
WithVaultCredentials { | |
sh """ | |
vault kv put ${config.secretPath} ${key}=${config.value} | |
""" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment