小编Eka*_*lbs的帖子

Jenkins 管道抛出 java.io.NotSerializableException: org.jenkinsci.plugins.workflow.job.WorkflowRun 即使使用 @NonCPS

代码相当简单,我只想要一个 rev-list 发布到 slack。但是导致我出现问题的部分是当我实际上试图从 git 获取 rev-list 时。

问题代码

@NonCPS
def getRevisionList(currentCommit, lastSuccessfulCommit) {
     def commits = sh(
        script: "git rev-list $currentCommit $lastSuccessfulCommit",
        returnStdout: true
    ).split('\n')
    echo "$commits"
}
Run Code Online (Sandbox Code Playgroud)

完整代码:

@NonCPS
def getRevisionList(currentCommit, lastSuccessfulCommit) {
     def commits = sh(
        script: "git rev-list $currentCommit $lastSuccessfulCommit",
        returnStdout: true
    ).split('\n')
    echo "$commits"
}
Run Code Online (Sandbox Code Playgroud)

詹金斯给我的错误是这样的:

an exception which occurred:
in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@76bde0fe
in field com.cloudbees.groovy.cps.impl.CallEnv.caller
in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@662f031a
in field com.cloudbees.groovy.cps.Continuable.e
in object org.jenkinsci.plugins.workflow.cps.SandboxContinuable@1156ea7f
in field org.jenkinsci.plugins.workflow.cps.CpsThread.program
in object org.jenkinsci.plugins.workflow.cps.CpsThread@5bada334
in …
Run Code Online (Sandbox Code Playgroud)

git groovy jenkins-pipeline

7
推荐指数
1
解决办法
6901
查看次数

标签 统计

git ×1

groovy ×1

jenkins-pipeline ×1