jenkins 管道中的 changeSet 出错(错误:java.io.NotSerializableException:hudson.plugins.git.GitChangeSetList) [英] Error with changeSet in jenkins pipeline (Error:java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList)

查看:12
本文介绍了jenkins 管道中的 changeSet 出错(错误:java.io.NotSerializableException:hudson.plugins.git.GitChangeSetList)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个错误:

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

ChangeSet!=null 但奇怪的是更新此插件时出现错误:Pipeline Shared Groovy Libraries,在此之前工作良好,我使用 jenkins v 2.21 和 pipeline 2.4,我的代码是下一个:

when ChangeSet!=null but the strange is that the error ocurred when updating this plugin: Pipeline Shared Groovy Libraries, before this work good, i use jenkins v 2.21 and pipeline 2.4 and my code is the next:

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 开头的函数中这样做.例如:

Jenkins jobs can be saved in mid execution, which requires them to be serialized. The contents of rawBuild cannot be serialized, so if you access this, you need to do so within a function that is prefaced with @NonCPS. E.g.:

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}"
          }
      }
  }
}

这篇关于jenkins 管道中的 changeSet 出错(错误:java.io.NotSerializableException:hudson.plugins.git.GitChangeSetList)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆