tomcat - Groovy 帮助查找丢失的包 : com. cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials package not found, Jenkins Job DSL plugin

标签 tomcat groovy jenkins-job-dsl

我是 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

任何帮助将不胜感激

最佳答案

自 Job DSL 插件版本 1.43 起,来自 Credentials 插件的类在 DSL 脚本中不再可用。因此,您在更新 Jenkins 时可能还更新了 Job DSL 插件。

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

关于tomcat - Groovy 帮助查找丢失的包 : com. cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials package not found, Jenkins Job DSL plugin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40457223/

相关文章:

java - Tomcat 8.0 不会以纯 Spring MVC 模板启动

java - <welcome-file-list> 在 Tomcat 中被忽略

Android AlertDialog Builder 更好的代码

grails - 呈现与 Action 同名的 View 时,Grails重定向循环错误

jenkins - job-dsl-core jar 版本更新至 1.44 & githubPullRequest 关闭不起作用

jenkins-job-dsl - 如何使用凭据参数设置 git 凭据

Jenkins 使用 DSL 将 git 子模块添加到 multibranchPipelineJob

java - 当并发 session 过多时,Java Web 容器的内存会发生什么变化?

java - 如何从 sql server 2005 读取 java Servlet 中的阿拉伯字母?

gradle - 如何向 flyway build.gradle 文件添加参数?