Brian Johnson
Brian Johnson

Reputation: 13

How can I store shell output into an array in Jenkins?

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?

Upvotes: 1

Views: 2182

Answers (1)

Bhanuchander Udhayakumar
Bhanuchander Udhayakumar

Reputation: 1621

Can be done in groovy way:

gitBranchStr  = sh (
script: 'git branch -a',
returnStdout: true)
gitBranchList = gitBranchStr.substring(gitBranchStr.lastIndexOf("*") + 1).split("\n")*.trim()

Upvotes: 1

Related Questions