Error with changeSet in jenkins pipeline (Error: java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList)

I have this error:

java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList 

when ChangeSet!=null , but it’s strange that an error occurred while updating this plugin: “General information about Groovy pipelines”, before this work, I use jenkins v 2.21 and pipe 2.4, and my code is as follows:

 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 
+5
source share
1 answer

Jenkins jobs can be saved in the middle of execution, which requires serialization. The contents of rawBuild cannot be serialized, so if you access it, you need to do this as part of the function that @NonCPS . For instance:.

 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}" } } } } 
+5
source

Source: https://habr.com/ru/post/1257543/


All Articles