我是 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
我要引用的特定类:
任何帮助将不胜感激
最佳答案
自 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/