我在“PreVerifymanager.groovy”中实现了我的 GParsPool.withPool,如下所示。
import groovyx.gpars.GParsPool
public class PreVerifyManager {
static final THREADS = 3;
public void callMe() {
PreVerifyManager pf = new PreVerifyManager()
def apps = ["App1","App2","App3"]
GParsPool.withPool(PreVerifyManager.THREADS) {
apps.eachParallel {
pf.CreateFile(it)
}
}
}
public void CreateFile(String path){
path = "D:\\"+path+".txt";
println(path)
File file = new File(path)
file.write("Some text")
}
}
这在我的 IDE 中使用 PreVerifyManager 的主要方法可以正常工作。但是当我删除 main 方法并在 Pipeline 脚本中创建的 PreVerifyManager 的对象上调用方法 callMe 时,它不起作用。
管道脚本如下:
node {
def PreVerifyManagerObj
stage 'TibcoConfig'
echo 'Reading Tibco configuration!'
println "****************INSIDE PIPELINE****************"
def parent = getClass().getClassLoader()
def loader = new GroovyClassLoader(parent)
PreVerifyManagerObj = loader.parseClass(new File("D://Tibco_Automation//src//com//meet//PreVerifyManager.groovy")).newInstance()
PreVerifyManagerObj.callMe()
}
基本上,我正在将 GParsPool.withPool 实现与管道脚本集成。任何输入表示赞赏。