0

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]

1 Answer 1

3

Short answer

List hashes = commitInfoAll*.commitId

Long answer

List hashes = commitInfoAll.collect{ it.commitId }
Sign up to request clarification or add additional context in comments.

2 Comments

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such field found: field com.github.jenkins.lastchanges.model.CommitInfo Commit
you provided an example with Commit field present. Based on github.com/jenkinsci/last-changes-plugin/blob/master/src/main/… you should replace it with commitId

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.