小编典典

jenkins管道中的changeSet错误(错误:java.io.NotSerializableException:hudson.plugins.git.GitChangeSetList)

jenkins

我有这个错误:

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

ChangeSet!=null但奇怪的是,更新此插件时发生错误:管道共享Groovy库,在此工作正常之前,我使用jenkins v
2.21和管道2.4,而我的代码是下一个:

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

阅读 704

收藏
2020-07-25

共1个答案

小编典典

Jenkins作业可以保存在执行中,这需要对它们进行序列化。rawBuild的内容无法序列化,因此,如果要访问它,则需要在以开头的函数中进行序列化@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}"
          }
      }
  }
}
2020-07-25