Last active
June 14, 2020 16:40
-
-
Save solvingj/94927c0dd13fbf2cb397e7d82b2e0a22 to your computer and use it in GitHub Desktop.
Iterable withIndex behavior discrepancy on Jenkins
This file contains hidden or 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
// Run this in a Jenkins step | |
String jsonStr = "['zero', 'one', 'two']" | |
JSONArray jsonArray = new JsonSlurper().parseText(jsonStr) as JSONArray | |
jsonArray.withIndex().each{Object str, Integer idx -> currentBuild.echo("${idx.toString()} : ${str}")} | |
// OUTPUT from jenkins | |
// [Pipeline] echo | |
// null : [zero, 0] | |
// [Pipeline] echo | |
// null : [one, 1] | |
// [Pipeline] echo | |
// null : [two, 2] | |
// Run this locally in a groovy file or unit test | |
String jsonStr = "['zero', 'one', 'two']" | |
JSONArray jsonArray = new JsonSlurper().parseText(jsonStr) as JSONArray | |
jsonArray.withIndex().each{Object str, Integer idx -> println("${idx.toString()} : ${str}")} | |
// OUPUT Local | |
// 0 : zero | |
// 1 : one | |
// 2 : two | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment