[英]Using global shared libraries in Jenkins to define parameter options
我正在嘗試使用我在共享庫中定義的全局類來幫助組織作業參數。 它不起作用,我什至不確定是否可能。
我的工作是這樣的:
pipelineJob('My-Job') {
definition {
// Job definition goes here
}
parameters {
choiceParam('awsAccount', awsAccount.ALL)
}
}
在 /vars/awsAccount.groovy 的文件中,我有以下代碼:
class awsAccount implements Serializable {
final String SANDPIT = "sandpit",
final String DEV = "dev",
final String PROD = "prod"
static String[] ALL = [SANDPIT, DEV, PROD]
}
全局管道庫配置為從我的存儲庫的主分支隱式加載。
嘗試更新 DSL 腳本時,我收到錯誤消息:
錯誤:(myJob.groovy,第 67 行)沒有這樣的屬性:類的 awsAccount:javaposse.jobdsl.dsl.helpers.BuildParametersContext
為什么它找不到類,甚至可以在管道作業中使用這樣的共享庫類?
免責聲明:我知道它可以使用 Jenkinsfile 工作。 不幸的是,沒有測試過使用聲明性管道 - 但還沒有答案,所以可能值得一試
關於您的第一個問題:有一些原因導致無法找到您的共享庫中的類。 從庫導入、庫語法等開始。但它們絕對適用於 DSL。 更准確地說,額外的信息會很棒。 但請確保:
import
使用的名稱完全相同import
(在Using Libraries 下)關於您的第二個問題(命名此 SO 問題的問題):是的,您可以從共享庫中的信息中包含參數作業。 至少,使用 Jenkinsfiles。 您甚至可以定義要包含在管道中的屬性。 由於不同的問題,我得到了一個棘手的語法。
同樣,我正在使用Jenkinsfile ,這對我有用:
class awsAccount implements Serializable { // static giveMeParameters (script) { return [ // Some parms script.string(defaultValue: '', description: 'A default parameter', name: 'textParm'), script.booleanParam(defaultValue: false, description: 'If set to True, do whatever you need - otherwise, do not do it', name: 'boolOption'), ] } }
properties ( parameters ( awsAccount.giveMeParameters (this) )
再次注意調用函數時的語法。 與此類似,您還可以在共享庫中定義返回屬性並在多個作業中使用它們的函數( disableConcurrentBuilds 、 buildDiscarder等)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.