Issue
I'm using multibranch pipeline and i need to get the list of modified files.
i tried
git diff $PREVIOUS_COMMIT $COMMIT
but they have the same SHA.
Solution
According to this article at CloudBees, you can access such information inside a pipeline also without white-listing (using Sandbox / script security, compared to my other answer), starting from workflow-support Plugin version 2.2:
def changeLogSets = currentBuild.changeSets
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]
echo "${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}"
def files = new ArrayList(entry.affectedFiles)
for (int k = 0; k < files.size(); k++) {
def file = files[k]
echo " ${file.editType.name} ${file.path}"
}
}
}
Answered By - StephenKing