【问题标题】:Import library into Jenkins groovy script将库导入 Jenkins groovy 脚本
【发布时间】:2017-02-23 16:32:28
【问题描述】:

在我的 Jenkins 构建中,我有一个 Groovy 脚本(因为我使用的是 Pipeline 插件),我正在尝试使用 OkHttpClient 进行 API 调用。

我有以下从here 获得的葡萄代码:

@Grapes(
    @Grab(group='com.squareup.okhttp', module='okhttp', version='2.7.5')
)

为此,我得到:

General error during conversion: Error grabbing Grapes -- [unresolved dependency: com.squareup.okkhttp#okhttp;2.7.5: not found]

java.lang.RuntimeException: Error grabbing Grapes -- [unresolved dependency: com.squareup.okhttp#okhttp;2.7.5: not found]
at sun.reflect.NativeContructorAccessorImpl.newInstance0(Native Method)

知道可能出了什么问题吗?

在 Jenkins 流水线脚本中运行时,Grape 无法检索包?

【问题讨论】:

  • jenkins 版本是什么?
  • 版本是2.46
  • 是否安装了Pipeline Shared Groovy Libraries Plugin。他们从 2.3 版开始支持@Grab
  • 我安装了这个插件并重新启动了 Jenkins,但我得到了同样的错误。
  • 还没有。 ticket 仍然打开

标签: jenkins groovy jenkins-pipeline groovy-grape


【解决方案1】:

我在运行使用 @Grab 注释的 Jenkins Groovy 控制台脚本时遇到了类似的问题。该错误是由 Jenkins Groovy 无法解析我的公司代理主机服务器引起的。

Groovy 代理服务器可以在命令行中设置,如下所示:

groovy -Dhttp.proxyHost=yourproxy -Dhttp.proxyPort=portNumber yourscript.groovy

但我不知道如何为 Jenkins Groovy 做到这一点。

我以以下解决方法结束:

您可以从命令行安装所需的库(假设您可以访问 Jenkins 服务器)。在这种情况下,代理服务器很容易指定如下:

grape -Dhttp.proxyHost=proxy.server.net -Dhttp.proxyPort=port install %groupId% %artifactId% [%version%]

还要确保在使用 Jenkins 用户帐户登录时安装库。 Grapes 库是特定于用户帐户的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-02
    • 2012-06-29
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 2013-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多