【问题标题】:Groovy help find missing package: com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials package not found, Jenkins Job DSL pluginGroovy 帮助查找丢失的包:com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials package not found, Jenkins Job DSL plugin
【发布时间】:2023-03-17 12:48:01
【问题描述】:

我是 groovy 的新手,目前正在尝试将我的团队 Jenkins 服务器从 1.6 更新到 2.7。我需要迁移的部分之一是我们在版本控制中拥有的 Job DSL。

在新服务器上尝试运行旧作业 DSL 时出现以下错误:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/apps/Jenkins/workspace/DSL-infrastructure/shared/Shared.groovy: 10: Apparent variable 'com' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable from a static context.
You misspelled a class name or statically imported field. Please check the spelling.
You attempted to use a method 'com' but left out brackets in a place not allowed by the grammar.
 @ line 10, column 17.
       def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
                   ^

基本上,我认为问题在于 groovy 脚本找不到 com.cloudbees... 包。

Shared.groovy 脚本部分:

  static def getCred(partialName) {
    def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
      com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class,
      jenkins.model.Jenkins.instance,
      null,
      null
    )
    creds.find { it.description.contains(partialName) }
  }

我已经到处搜索了,但我终其一生都无法弄清楚为什么或如何解决这个丢失的包裹问题。当我在 apache tomcat 中运行 Jenkins 时,它变得很复杂。

我不确定如何在运行 Jenkins 的 apache tomcat 服务器中导入这个丢失的包?我在目录中找到了 .jar 文件:

/apps/jenkins/plugins/credentials/WEB-INF/lib/credentials.jar

我试图引用的特定类:

https://github.com/jenkinsci/credentials-plugin/blob/master/src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java

任何帮助将不胜感激

【问题讨论】:

    标签: tomcat groovy jenkins-job-dsl


    【解决方案1】:

    自 Job DSL 插件版本 1.43 起,来自 Credentials 插件的类不再在 DSL 脚本中可用。所以你可能在更新 Jenkins 时也更新了 Job DSL 插件。

    Credentials plugin 的 1.21+ 版本允许为凭据指定自定义 ID,因此不必通过描述查找凭据。只需使用描述性 ID。

    【讨论】:

    • 感谢 daspilker 的回复。我有一种直觉,我需要重写 Job DSL。如果我想出一个答案,我会试一试并在这里发布我的答案。
    • 您能否举例说明它如何仅与 Credentials 插件一起使用?
    【解决方案2】:

    一种方法是使用Credential Binding 插件,该插件允许按照daspilker 的建议使用已定义的Jenkins 全局credentials。 下面是一个从 SVN url 列出文件夹结构的作业示例(它对其他 repos 的工作方式类似)。请注意,您需要连接秘密,使用格式化程序会将其屏蔽并且不会被识别(为简单起见,以下用户未连接)。

    【讨论】:

      猜你喜欢
      • 2017-06-21
      • 2015-03-25
      • 2016-01-04
      • 2016-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-06
      相关资源
      最近更新 更多