我正在努力將整個 Jenkins 從正常作業轉變為 DSL/Pipelines。必須為所有匯入實作一個共享庫。在上述庫中有大量腳本。目前,它們都是這樣設定的:
package common
class Foo {
static String bar(String text) { stuff }
static String bar2(String text) { stuff }
static String bar3(String text) { stuff }
}
在管道中:
#!/usr/bin/env groovy
@Library('jenkins-shared-libs') _
import common.*
有許多腳本和許多方法。我如何,在哪里,以及不能使用 call() 來實際“呼叫”它們嗎?
uj5u.com熱心網友回復:
如果您想呼叫類中的bar方法,Foo您可以執行以下任一操作:
選項1:
common.Foo.bar('some argument')
選項 2:
import common.*
Foo.bar('some argument')
選項 3:
import static common.Foo.*
bar('some argument')
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/395859.html
上一篇:比較詹金斯管道中的兩個串列
