Reputation: 53
I have a string in groovy where every item is a new line
change_list = sh returnStdout: true, script: 'cd $WORKSPACE/p4c && git diff ${cid} origin/${CHANGE_TARGET} --name-only'
print change_list
print change_list.getClass()
Below is the output
Jenkinsfile
extensions/idpf/BaseCtrlTables.cpp
extensions/idpf/CollectProgramData.cpp
extensions/idpf/CollectProgramData.h
extensions/idpf/FormApplyTree.cpp
I want to convert it into a string with the newline changed as comma separated, or a new list with each element as 1 item
Upvotes: 1
Views: 438
Reputation: 28599
List list = change_list.readLines()
https://docs.groovy-lang.org/latest/html/groovy-jdk/java/lang/CharSequence.html#readLines()
Or
String[] array = change_list.split(/\n/)
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#split-java.lang.String-
Upvotes: 2