Skip to content

Instantly share code, notes, and snippets.

@abdennour
Last active May 21, 2020 15:30
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 abdennour/873aaf5599a96cc88599cea7f008e89a to your computer and use it in GitHub Desktop.
Save abdennour/873aaf5599a96cc88599cea7f008e89a to your computer and use it in GitHub Desktop.
Jenkins steps for vault
#!/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}"
"""
}
}
ReadVaultSecret {
vaultNamespace = "secret/devops/${currentEnv}/"
chartPath = currentPath
secretPath = "kubeconfig"
}
WriteVaultSecret {
secretPath = "secret/projects/helm/${project}/${currentEnv}/${currentApp}-${currentEnv}/${it.key}"
value = it.value
}
#!/usr/bin/env groovy
def call(body){
withCredentials([
string(credentialsId: 'VAULT_ADDR', variable: 'VAULT_ADDR'),
string(credentialsId: 'VAULT_TOKEN', variable: 'VAULT_TOKEN')]) {
body()
}
}
#!/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