Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add githubChangeset, retrieves latest commits for build #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions vars/githubChangeset.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// vars/githubChangeset.groovy
// Iterates over commits since the last build and outputs them
// in the following format via echo:
// - Commit message [author]

def call() {
def changeString = ""
def changeLogSets = currentBuild.changeSets

// Iterate over changes and add them to changeString
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
changeString += " - ${entry.msg} [${entry.author}]\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timestamp would be nice per https://support.cloudbees.com/hc/en-us/articles/217630098-How-to-access-Changelogs-in-a-Pipeline-Job-

Also, it would be awesome to do this with pure shell, but I guess the hard part is figuring out the last built commit - git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit 68e07c5

}
}

if (!changeString) {
changeString = " - No new changes\n"
}

changeString = "SCM Changes:\n------------------------------------------------------------\n" +
changeString + "-------------------------------------------------------------";
echo changeString
}