Jenkins 管道作业报告 Groovy 绑定(bind)错误

标签 jenkins groovy jenkins-pipeline

我有一个 Jenkins 作业,它加载一个定义要运行的管道的 groovy 文件。当我运行此作业时,它报告错误 - groovy.lang.MissingPropertyException: No such property: ¡ for class: groovy.lang.Binding (堆栈跟踪如下)。

昨天还可以工作,但莫名其妙地停止了工作。我已经搜索了文档,用 google 搜索了错误并尽可能简化了工作和常见的 groovy 文件,但到目前为止无法识别问题。

我的问题是,以前有人见过这个问题吗?如果有的话,根本原因和解决方案是什么?

管道作业脚本:

#!groovy

node
{
    def pipeline = load "CommonPipeline.groovy"
    pipeline.run()
}

CommonPipeline.groovy:

#!groovy
​
def run()
{
     echo "#### THIS WORKS! ####"
}

return this

堆栈跟踪:

Started by user jenkins
[Pipeline] node
Running on Worker in c:\path\to\script\groovy-test
[Pipeline] {
[Pipeline] load
[Pipeline] { (CommonPipeline.groovy)
[Pipeline] }
[Pipeline] // load
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: ​ for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:224)
    at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:241)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:238)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:28)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
    at Script1.run(Script1.groovy:2)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
    at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
    at com.cloudbees.groovy.cps.Next.step(Next.java:58)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:163)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:324)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:78)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:236)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:224)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:63)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Finished: FAILURE

最佳答案

愚蠢的错误 - 当您的文件扩展名是 .groovy 时,不需要“shebang” header 语句#!groovy。我从 CommonPipeline.groovy 中删除了它,现在工作正常了。我认为这不会有任何区别!

奇怪的是,自从它昨天停止工作以来我就没有改变它。我能想到的唯一改变是我安装了一些 Jenkins 插件更新......

我会留下这个问题和解决方案,以防其他人遇到这个问题。 ​

关于Jenkins 管道作业报告 Groovy 绑定(bind)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40546705/

相关文章:

jenkins - 如何将jenkins作业移动到子文件夹?

php - 如何使 PHP 警告失败 PHPUnit 测试用例?

javascript - 如何通过图像查找元素

jenkins - 有没有办法在 Jenkins 中查看插件的所有可用方法?

jenkins - 更新声明性管道作业的 cron 触发器不会更新触发器

kubernetes - 是否可以在声明性管道的 Kubernetes pod 代理模板中使用 Jenkins secret 作为 imagePullSecret

python - 如何从 Jenkins 将 Python 应用程序部署到 Amazon Elastic Beanstalk?

git - jenkins:git fetch 返回状态代码 128: "object file ... is empty"

hibernate - Hibernate Create Criteria 中可以有 if 条件吗?

gradle - 基于抽象类在Gradle中分离集成测试与单元测试