Skip to content

Instantly share code, notes, and snippets.

@lepffm
Created October 4, 2019 05:11
Show Gist options
  • Save lepffm/910d78fe1d8d2ae12c15de37ea96f88f to your computer and use it in GitHub Desktop.
Save lepffm/910d78fe1d8d2ae12c15de37ea96f88f to your computer and use it in GitHub Desktop.
jenkins read hashicorp vault pipeline example
pipeline {
agent any
environment {
VAULT_TOKEN = 'YOUR_VAULT_TOKEN'
VAULT_API_ADDR = 'YOUR_VAULT_URL/v1'
}
stages {
stage("read vault"){
steps {
script{
txt = sh(returnStdout: true, script: "curl -s -H \"X-Vault-Token:$VAULT_TOKEN\" -X GET $VAULT_ADDR/your_secret_path/?list=true").trim()
json = new groovy.json.JsonSlurperClassic().parseText(txt)
json.data.keys.sort().each{ key ->
println "key=${key}"
txt = sh(returnStdout: true, script: "curl -s -H \"X-Vault-Token:$VAULT_TOKEN\" -X GET $VAULT_ADDR/your_secret_path/${key}").trim()
json = new groovy.json.JsonSlurperClassic().parseText(txt)
json.data.each{ entry ->
println entry.key + " = " + entry.value
}
}
}//script
}//steps
}
}//stages
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment