How to get "Changes Summary" into declarative pipeline?

23 views
Skip to first unread message

Vitaly Karasik

unread,
Jun 9, 2020, 3:55:42 AM6/9/20
to Jenkins Users
For each build in jenkins there is a page with a "Changes  Summary" of what happened in that build. I guess the same is available in 'when' condition as 'changelog'.
How I get the same text into my declarative pipeline? I found many examples using some plugins and scripts, but Jenkins core definitely knows this info.
What I'm missing?

TIA, Vitaly


Bruce Coveny

unread,
Jun 9, 2020, 1:09:34 PM6/9/20
to Jenkins Users
Hi Vitaly,

Not sure if it helps but this is a Groovy script that I use to obtain the change details.  Change details are not always available as it depends on pulling in a Git commit to obtain and sometimes (for instance rebuilding) it may not have those changes.  I think what you are referring to is that Jenkins has the information in the object currentBuild.changeSets which is a collection of the changes.  It took me a while to find out some of the details to display here but I think this script kind of mimics what Jenkins shows on the change summary.

def call() {
def changeText = StringBuilder.newInstance()
for (changeSet in currentBuild.changeSets) {
for (item in changeSet.items) {
def shortCommitId = item.commitId.substring(0,12)
changeText.append("Commit ${shortCommitId} by *${item.author}*, ${item.msg}\n")
}
}
if (changeText.length() == 0) {
changeText.append("No Changes Identified.")
}
return changeText.toString()
}

Sample output:
Commit {partial_commit_string_1} by *{author_1}*, {message_from_commit_1}
Commit {partial_commit_string_2} by *{author_2}*, {message_from_commit_2}

Hopefully this helps.

Bruce
Reply all
Reply to author
Forward
0 new messages