Shahar Hamuzim Rajuan
Shahar Hamuzim Rajuan

Reputation: 6129

Get string from array in groovy

I have this array called commitInfoAll in my Jenkins pipeline, I'm trying to get only the commit hashes from this array into another list/array. the number of commits can be 1,2,3...n.

commitInfoAll: 
  [Commit: acaf95bf73804bb3a3c10b0352c2d566506c26f5
  Author: Shachar
  E-mail: [email protected]
  Date: Oct 30, 2019 11:38:43 AM GMT+02:00
  Message: Getting commit info (schedulertCommitInfo) #2


  , Commit: a1720a49e7f0ed98c25a4119ae961b71d7e3fdc3
  Author: Shachar
  E-mail: [email protected]
  Date: Oct 30, 2019 11:38:24 AM GMT+02:00
  Message: Getting commit info (schedulertCommitInfo)
 ]

What I want to get in the end is an array like this :

[acaf95bf73804bb3a3c10b0352c2d566506c26f5,a1720a49e7f0ed98c25a4119ae961b71d7e3fdc3,...and so on]

Upvotes: 0

Views: 223

Answers (1)

injecteer
injecteer

Reputation: 20699

Short answer

List hashes = commitInfoAll*.commitId

Long answer

List hashes = commitInfoAll.collect{ it.commitId }

Upvotes: 3

Related Questions