我正面临着Jenkins共享库的问题。失败时出现以下错误。
an exception which occurred:
in field org.codehaus.groovy.control.MultipleCompilationErrorsException.collector
in object org.codehaus.groovy.control.MultipleCompilationErrorsException@545ac2e4
in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@633a4023
in field com.cloudbees.groovy.cps.impl.CallEnv.caller
in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@4fc67d86
in field com.cloudbees.groovy.cps.Continuable.e
in object com.cloudbees.groovy.cps.Continuable@398d975c
in field org.jenkinsci.plugins.workflow.cps.CpsThread.program
in object org.jenkinsci.plugins.workflow.cps.CpsThread@45695fe5
in field org.jenkinsci.plugins.workflow.cps.CpsBodyExecution.thread
in object org.jenkinsci.plugins.workflow.cps.CpsBodyExecution@584b34fe
in field org.jenkinsci.plugins.workflow.cps.CpsBodyExecution$SuccessAdapter.this$0
in object org.jenkinsci.plugins.workflow.cps.CpsBodyExecution$SuccessAdapter@20f23f9f
Caused: java.io.NotSerializableException:org.codehaus.groovy.control.ErrorCollector
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
Groovy Vars代码
import org.com.*
def call(string project, string repo){
gt = new git(this, project, repo)
gt.gitclone('pip','ospatchingpipeline' )
git(this, project)
}
来源类
package org.com.*
/**
* Created by mishrav on 12/14/2017.
*/
class git implements Serializable {
def project
def repo
git(string project, string repo) {
this.project = project
this.repo = repo
}
def gitclone(project, repo){
echo(" cloning ${project}")
git url: "ssh://git@bitbucket:7999/${project}/${repo}.git"
}
}
管道代码
@Library('pipelineLibrary') _
import java.util.regex.Pattern
//def lib = library("pipelineLibrary").com.clsa.scm.git()
//library identifier: 'pipelineLibrary@master', retriever: modernSCM([$class: 'GitSCMSource',remote: 'ssh://git@bitbucket:7999/pip/pipelinelibrary.git',credentialsId: 'my-private-key'])
pipeline {
agent any
stages{
stage ('cleaning workspace'){
steps{
script{
checkoutScm("ospatchingpipeline")
}
}
}
}
}
我不确定在上传之前是否需要编译此代码。
答案 0 :(得分:0)
当您使用未实现 Serializable 接口的函数(访问要导入的类的对象)时,会发生此错误。
当我们由于以下功能而遇到此问题时:
@NonCPS
private static boolean isDebugOn (ParamType param1) { ...
删除static
并将其更改为消除此错误:
@NonCPS
private boolean isDebugOn (ParamType param1) { ...
似乎是@NonCPS
和static
的组合导致了该错误。
当您使用的方法使用无法序列化的对象时,@ NonCPS注释将非常有用。通常,您在管道脚本中创建的所有对象都必须可序列化(原因是Jenkins必须能够序列化脚本的状态,以便可以将其暂停并存储在磁盘上)。
将@NonCPS放在方法上时,Jenkins将一次性执行整个方法,而不会暂停。同样,您不能从@NonCPS注释的方法中引用任何管道步骤或CPS转换的方法。 More information about this can be found here.