我有这个错误:
java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList
当ChangeSet!=null但奇怪的是,更新此插件时发生错误:管道共享Groovy库,在此工作正常之前,我使用jenkins v 2.21和管道2.4,而我的代码是下一个:
ChangeSet!=null
def changeLogSets = currentBuild.rawBuild.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}" } } } changeLogSets= null
Jenkins作业可以保存在执行中,这需要对它们进行序列化。rawBuild的内容无法序列化,因此,如果要访问它,则需要在以开头的函数中进行序列化@NonCPS。例如:
@NonCPS
showChangeLogs() @NonCPS def showChangeLogs() { def changeLogSets = currentBuild.rawBuild.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}" } } } }