Last active
February 23, 2018 18:44
-
-
Save cdenneen/6c23b2a635fa013e6d578c9d7c8ccee2 to your computer and use it in GitHub Desktop.
Jenkins parse json
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
//@NonCPS | |
def parseText(txt){ | |
return new groovy.json.JsonSlurperClassic().parseText(txt) | |
} | |
node ('master') { | |
variables = parseText(new File('/tmp/test.json').text) | |
// this works | |
def out = variables.dne.prod.dashboard.stacknameprefix | |
print out | |
// this also works | |
print variables.dne.prod.dashboard.stacknameprefix | |
// and this also works | |
def var = 'dne.prod' | |
print evaluate('variables.' + var + '.dashboard.stacknameprefix') | |
// or this | |
def val = 'dne.prod' | |
def map_file = '/tmp/test.json' | |
def map = readJSON file: map_file | |
def string = 'dne.prod' | |
// this is currently broken in jenkins... patching coming | |
//def (one, two) = string.tokenize('.') | |
def array = string.tokenize('.') | |
def val1 = 'dne' | |
def val2 = 'prod' | |
def map_file = '/tmp/test.json' | |
def map = readJSON file: map_file | |
print map."${val1}"."${val2}".dashboard.stacknameprefix | |
print map."${array[0]}"."${array[1]}".dashboard.stacknameprefix | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment