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

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

问题描述

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

when 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.author} $ {entry.author} $ {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


解决方案

保存在执行中,这就要求它们被序列化。 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 $ {entry.author} $ {entry.mitId}对于(int j = 0; j def entry = entries [j]
echo $ {entry.commitId} 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}
}
}
}
}


I have this error:

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

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 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 pipeline中changeSet的错误(错误:java.io.NotSerializableException:hudson.plugins.git.GitChangeSetList)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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