Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jenkins管道中的变更集出错(错误:java.io.NotSerializableException:hudson.plugins.git.GitChangeSetList)_Git_Jenkins_Jenkins Pipeline_Changeset - Fatal编程技术网

jenkins管道中的变更集出错(错误:java.io.NotSerializableException:hudson.plugins.git.GitChangeSetList)

jenkins管道中的变更集出错(错误:java.io.NotSerializableException:hudson.plugins.git.GitChangeSetList),git,jenkins,jenkins-pipeline,changeset,Git,Jenkins,Jenkins Pipeline,Changeset,我有一个错误: java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList 当变更集=null但奇怪的是,更新此插件时出现了错误:管道共享Groovy库,在这项工作正常之前,我使用jenkins v 2.21和管道2.4,我的代码是下一个: def changeLogSets = currentBuild.rawBuild.changeSets for (int i = 0; i < changeLogSet

我有一个错误:

java.io.NotSerializableException: hudson.plugins.git.GitChangeSetList
当<代码>变更集=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
def changeLogSets=currentBuild.rawBuild.changeSets
对于(int i=0;i
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}"
          }
      }
  }
}
showChangeLogs()
@非现金
def showChangeLogs(){
def changeLogSets=currentBuild.rawBuild.changeSets
对于(int i=0;i
我想提供另一个答案,以BMitch的答案为基础
rawBuild
方法带来了安全问题,并在Jenkins文件中被阻止。在较新版本中,
currentBuild
对象直接公开
changeSets
,因此您可以像这样使用脚本

@NonCPS
def showChangeLogs() {
    def changeLogSets = currentBuild.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}"
            }
        }
    }
}
@NonCPS
def showChangeLogs(){
def changeLogSets=currentBuild.changeSets
对于(int i=0;i
如果showChangeLogs位于导入到的库中,则这似乎没有帮助Jenkinsfile@gerasalus我在一个共享库中遇到了这个问题。。。您找到解决方案了吗?您好@MarcellodeSales,我刚刚处理了相同的问题,但在共享库中的方法解决异常之前使用\@NonCPS注释。@SimoneMarcato是的,这也解决了我们的问题!非常感谢。