I am using groovy in jenkins and there is this string that i need to get the last word in it. Let just say the string is STATUS = "EXECUTE SIT". So what I did was to split the string so that I will get an array STATUS.split() and then pop so that i can get SIT string STATUS.split().pop(). But it returns an error No signature of method: java.lang.String.pop() I am not that familiar with Groovy or Java so I don't really know if I'm using these methods correctly.
1 Answer
I'm pretty sure the error you're getting is actually No signature of method: [Ljava.lang.String;.pop() is applicable for argument types: () values: []. Note the [L - this means you have an array, not a List.
split() returns an array of Strings (String[]) which doesn't support using pop() or many other of Groovy's enhancements.
Instead use tokenize() which returns a List. Once you have a list, you can use pop() or more appropriately, last(). pop() was changed in Groovy 2.5 to remove the first item instead of the last. Use removeLast() if you actually want to remove the last item.
"EXECUTE SIT".tokenize().last()
===> SIT
String[] tokens = STATUS.split()then do the poptokens.pop()popmethod?