Skip to content

Instantly share code, notes, and snippets.

@waltervargas
Created May 15, 2017 16:57
Show Gist options
  • Save waltervargas/4a26926fb8c86c7e44a0df0f65f8fba2 to your computer and use it in GitHub Desktop.
Save waltervargas/4a26926fb8c86c7e44a0df0f65f8fba2 to your computer and use it in GitHub Desktop.
aws sts assume role from jenkinsfile
// Receive a json and returns a groovy map
def _dict_from_json(json){
json = json.replaceAll("\\{", "[")
json = json.replaceAll("\\}", "]")
def map = evaluate(json)
return map
}
def _aws_assume_role(arn, session_name){
def _script = "aws sts assume-role --role-session-name ${session_name} --role-arn ${arn}"
def assume_role_output = sh (script: _script, returnStdout: true)
return assume_role_output
}
node ('master'){
stage('test') {
def json_output = _aws_assume_role(arn, "session-name")
def assume_role = _dict_from_json(json_output)
echo assume_role.Credentials.SecretAccessKey
echo assume_role.Credentials.AccessKeyId
echo assume_role.Credentials.SessionToken
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment