2016-11-07 187 views
1

我是groovy新手,目前正試圖將我的團隊Jenkins服務器從1.6更新到2.7。我需要遷移的一個部分是我們在版本控制中使用的Job DSL。Groovy幫助查找丟失的軟件包:未找到com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials軟件包,Jenkins 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

任何幫助,將不勝感激

回答

0

自1.43版本作業DSL插件,來自證書插件的類在DSL腳本中不再可用。所以你在更新Jenkins時可能也更新了Job DSL插件。

Credentials plugin的1.21+版本允許指定憑證的自定義ID,因此不需要按說明查找憑證。只需使用描述性ID即可。

+0

感謝您對daspilker的回覆。我有一種直覺,我需要重寫Job DSL。如果我想出一個答案,我會放棄並在此發佈我的答案。 –

+0

你能舉一個例子說明它如何與憑證插件一起工作嗎? – misha

0

一種方法是使用Credential Binding插件,該插件允許按照daspilker的建議使用已定義的Jenkins全球credentials。 下面是一個列出SVN網址的文件夾結構的作業示例(它將與其他回購相似)。請注意,您需要連接祕密,使用formater會掩蓋它並且不會被識別(爲簡單起見,下面的用戶不是連接的)。

Jenkins Secrets

相關問題