当前位置: 首页 > 知识库问答 >
问题:

无法解析groovyx类。网http。詹金斯管道中的HTTPBuilder

赫连瑾瑜
2023-03-14

我有一个jenkins管道脚本,它是从jenkins的另一个实例导入的,在那里运行时没有错误。

在当前实例上,它因导入错误而失败

我无法修改脚本b/c我现在拥有它。

我不能补充:

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )

当我运行作业时,会出现如下错误

    unable to resolve class groovyx.net.http.HTTPBuilder
 @ line 2, column 1.
   import groovyx.net.http.HTTPBuilder
   ^
unable to resolve class groovyx.net.http.ContentType
 @ line 3, column 1.
   import static groovyx.net.http.ContentType. * 
   ^

我怎样才能导入超文本传输协议-Builder jar文件到我的詹金斯环境,而不修改脚本,或者有一个詹金斯插件导入jar文件?

这是堆栈跟踪(以防万一)

at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:958)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:554)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
    at groovy.lang.GroovyClassLoader.recompile(GroovyClassLoader.java:761)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:718)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell$TimingLoader.loadClass(CpsGroovyShell.java:160)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:775)
    at org.jenkinsci.plugins.workflow.cps.global.UserDefinedGlobalVariable.getValue(UserDefinedGlobalVariable.java:54)
    at org.jenkinsci.plugins.workflow.cps.CpsScript.getProperty(CpsScript.java:121)
    at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:34)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
    at idt.devops.GlobalBuildPipeline.runPipeline(/var/lib/jenkins/jobs/jenkins-spud/branches/master/builds/34/libs/coretech-devops-jenkins-globallib/src/idt/devops/GlobalBuildPipeline.groovy:37)
    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(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    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:83)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:35)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:331)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:82)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:243)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:231)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

共有1个答案

蒋波光
2023-03-14

我也有同样的问题。我试图在管道之外的函数中使用@Grab,然后我试图在使用声明性管道步骤导入的共享库函数中使用它,并得到了同样的问题。

直到我在配置为全局共享库的共享库中使用它,并使用@library()注释将其加载到我的管道中,它才起作用。

 类似资料:
  • 问题内容: 我正在尝试在詹金斯(Jenkins)中运行以下内容,但我得到任何建议的错误? 错误-为什么在shell脚本中不使用文件名重新填充? 问题答案: 我建议在双引号中运行bash命令,并转义和字符。考虑以下Jenkins管道示例脚本: 我在此示例中使用的文件包含: 当我运行它时,我得到以下控制台输出: 运行脚本文件后,将其内容更改为: 希望能帮助到你。

  • 问题内容: 已解决 :感谢S.Richmond的以下答复我需要取消所有类型的存储映射,这意味着将变量和使用后作废。 附加 :搜索此错误的人员可能有兴趣使用Jenkins管道步骤- 在此处查找更多信息。 我正在尝试使用Jenkins Pipeline从用户那里获取输入,该输入作为json字符串传递给作业。管道然后使用隔离器对此进行解析,然后选择重要信息。然后,它将使用该信息与不同的作业参数并行运行1

  • 下面是我简单的jenkins pipeline groovy脚本,它将用这两个阶段和我们想要构建的作业创建一个管道,我希望在job configuration下的脚本中每次都更新用于构建和代码分析的作业名,方法是从用户界面中获取数据,用户将使用Eclipse提供构建作业名和代码分析作业名- jenkinsfile脚本:-

  • 问题内容: 我有一个简单的maven项目,其中包含一些常用的测试工具。它在本地构建,但是在詹金斯上,我遇到了这个奇怪的错误(见下文)。 其他资讯: 它使用Maven在本地构建 设置与我们所有其他詹金斯项目相同(非常基本) 其他詹金斯版本工作正常 我尝试删除/root/.jenkins/workspace/testtools文件夹 我尝试删除该版本并为其重新命名 磁盘未满 我没有找到其他有关此特定问

  • 问题内容: 我们有几个Java项目。每个项目都有自己的交付管道。 所有管道都具有以下共同的步骤(简化): 建立项目 发布项目 部署到测试环境 部署到生产环境 项目管道仅在项目特定的属性(例如服务名称或测试和生产环境的IP地址)上有所不同。 问题是:我们如何避免所有项目都有共同之处?Jenkins的“管道作为代码”是否提供类似管道模板的内容? 我可以想象一个模板将在我们的项目管道中节省很多冗余代码/

  • 问题内容: 我已经使用Jenkins为我的node js应用程序创建了CI管道。我的管道包括诸如构建,单元测试,集成测试,代码分析等工作。我知道默认情况下,即使一个测试用例失败,构建也会失败。 问题答案: 您的单元测试脚本将需要处理数学和逻辑,以确定失败的测试百分比足以使整个工作失败。然后,您的单元测试脚本可以返回通过(零)或失败(其他任何结果),詹金斯将相应地标记构建。