In my Jenkins pipeline, I'm trying to get this output into an array:
gitBranches = sh (
script: 'git branch -a',
returnStdout: true).trim()
Is that possible?
Can be done in groovy way:
gitBranchStr = sh (
script: 'git branch -a',
returnStdout: true)
gitBranchList = gitBranchStr.substring(gitBranchStr.lastIndexOf("*") + 1).split("\n")*.trim()
* and then trim - or else you end up with a whitespace before the current branch. And for golfing you could use the spread operator instead of the collect.