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

标签 git jenkins jenkins-pipeline changeset

我有这个错误:

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

ChangeSet!=null 但奇怪的是更新这个插件时出现了错误:Pipeline Shared Groovy Libraries,在这个工作正常之前,我使用 jenkins v 2.21 和 pipeline 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

最佳答案

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

关于git - Jenkins 管道中的 changeSet 错误(错误 :java. io.NotSerializableException : hudson. plugins.git.GitChangeSetList),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39795652/

相关文章:

java - Jenkins "execute shell command"段字符串参数的使用

hudson - Jenkins 可以将工件存储在作业目录之外吗?

loops - 如何在 Jenkinsfile 的 for 循环中正确使用变量

jenkins - 如何将文件参数传递给 Jenkins 管道中的另一个构建作业?

iphone - 如何在 XCode 中设置 SVN 存储库?

git - .gitconfig 中的 [core] 有什么作用,如何设置?

svn - 将单个提交添加到 Git 存储库的根目录/将 Git 导出到 Subversion

python-2.7 - 等待 Jenkins 构建完成

jenkins - 可视化 Jenkins 管道中的构建步骤

git - 如何让我完成一次提交的更改?