Skip to content

Instantly share code, notes, and snippets.

@abuxton
Last active October 30, 2020 18:46
Show Gist options
  • Save abuxton/98c7b3e9ceddc6385c8d80059b4d7f20 to your computer and use it in GitHub Desktop.
Save abuxton/98c7b3e9ceddc6385c8d80059b4d7f20 to your computer and use it in GitHub Desktop.
jenkins minimal curl Gist
pipeline {
agent any
stages {
stage('Integration Tests') {
steps {
script {
def ROLE_ID = "REPLACE_WITH_ID"
def SECRET_ID = "REPLACE_WITH_ID"
/* sh '''
set +x
curl -k \
--request POST \
--data '{"role_id":"ROLE_ID","secret_id":"SECRET_ID"}' \
--header 'X-Vault-Namespace:NAMESPACE' \
https://VAULT_ADDR:8200/v1/auth/approle/login
'''
*/
def requestBody = """{"role_id": "${ROLE_ID}", "secret_id": "${SECRET_ID}"}"""
def response = httpRequest(ignoreSslErrors: true,
customHeaders: [[name: 'x-vault-namespace', value:'NAMESPACE']],
httpMode: 'POST',
requestBody: requestBody,
url: 'https://VAULT_ADDR/v1/auth/approle/login' )
println(response.content)
def jsonObj = readJSON(text: response.content)
println(jsonObj.auth.client_token)
def secretResponse = httpRequest(ignoreSslErrors: true,
customHeaders: [[name: 'x-vault-namespace', value:'NAMESPACE'], [name:'x-vault-token', value: jsonObj.auth.client_token]],
httpMode: 'GET',
url: 'https://VAULT_ADDR:8200/v1/kv/data/kv/secret' )
println(secretResponse.content)
}
}
}
}
}
@abuxton
Copy link
Author

abuxton commented Oct 30, 2020

sh """
set +x
curl -k
--request POST
--data '{"role_id":"${ROLE_ID}","secret_id":"${SECRET_ID}"}'
--header 'X-Vault-Namespace:NAMESPACE'
https://VAULT_ADDR:8200/v1/auth/approle/login
"""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment