简体   繁体   English

从 groovy 中的数组中获取字符串

[英]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.我在我的 Jenkins 管道中有这个名为commitInfoAll的数组,我试图只将该数组中的提交哈希值放入另一个列表/数组中。 the number of commits can be 1,2,3...n.提交的数量可以是 1,2,3...n。

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


  , Commit: a1720a49e7f0ed98c25a4119ae961b71d7e3fdc3
  Author: Shachar
  E-mail: Shachar@google.com
  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]

Short answer简短的回答

List hashes = commitInfoAll*.commitId

Long answer长答案

List hashes = commitInfoAll.collect{ it.commitId }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM