Jenkins - Groovy脚本在return语句后没有结束

时间:2017-01-05 08:38:33

标签: jenkins groovy custom-build-step

我正在尝试在Jenkins上运行预定的Groovy脚本但是我遇到了一些麻烦 - 虽然它达到了“返回”声明但它不会完成运行。

我正在使用内部依赖项和类,我找到了代码行,如果省略,脚本会成功返回。但不幸的是,我无法忽略这一行:(

你知道是什么原因可能导致Jenkins构建步骤太困难吗?

我注意到“罪魁祸首”代码行,内部运行以下内容: this.executorService.scheduleWithFixedDelay(this.eventsPublisher, 3L, 3L, TimeUnit.SECONDS);

是否有可能与Executor一起玩,与Jenkins构建步骤混在一起?

我会喜欢一些帮助, 非常感谢:)

更新:

代码:

import java.sql.DriverManager
import java.sql.ResultSet
import java.text.DateFormat
import java.text.SimpleDateFormat
import hudson.model.*


def verticaConn = null
def verticaStmt = null
def mongoConnection = null

try {

    println("start script: vertica_to_kafka")

    // get params
    def verticaHostName = System.getenv("verticaHostName") //dev=192.168.247.11:5433 prod=192.168.251.120:5433
    def verticaDbName = System.getenv("verticaDbName")
    def verticaTBName = System.getenv("verticaTBName")
    def bootstrapServers = System.getenv("bootstrapServers")
    def limitNum = System.getenv("limitNum").toInteger()
    def startTime = System.getenv("startTime")


    MyKafkaStringProducer producer = new MyKafkaStringProducer();
    producer.init()

    MyEventDao eventDao = new MyEventDao();
    eventDao.setStringProducer(stringProducer);

    Class.forName("com.vertica.jdbc.Driver")
    String verticaConnectionString = "jdbc:vertica://${verticaHostName}/${verticaDbName}"

    Properties verticaProp = new Properties();
    verticaProp.put("user", "user");
    verticaProp.put("password", "password");
    verticaProp.put("ConnectionLoadBalance", 1);

    verticaConn = DriverManager.getConnection(verticaConnectionString, verticaProp);
    verticaStmt = verticaConn.createStatement()

    // vertica execution timestamp
    long currentTS = System.currentTimeMillis()
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String startTS = "1970-01-01 00:00:00";

    String command= "select * from ${verticaTBName} where ts >'${startTS}' "
    if (limitNum > 0) command += "limit ${limitNum}"

    println("querying vertica")
    verticaStmt.execute(command)
    ResultSet results = verticaStmt.getResultSet()


    println("start to send data to kafka")
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    while(results.next()){
        long id = results.getLong("id");
        String domain = results.getString("domain");
        String text = results.getString("text");
        Date ts = dateFormat.parse(results.getString("ts"));
        MyEntity myEntity = new MyEntity(id, domain, text, ts);
        eventDao.saveEntity(myEntity);
    }

} catch (Exception e){
    println(e.printStackTrace())
} finally {
    println("going to release resources");
    if (verticaStmt != null){
        try{
            verticaStmt.close()
            println("vertica statement closed successfully!");
        } catch (Exception e) {
            //println("error in close the vertica statement {}", e.getMessage());
        }
    }
    if (verticaConn != null){
        try{
            verticaConn.close()
            println("vertica connection closed successfully!");
        } catch (Exception e) {
            //println("error in close the vertica connection {}", e.getMessage());
        }
    }

    if (mongoConnection != null){
        try {
            mongoConnection.getMongo().close();
            println("mongo connection closed successfully!");
        } catch (Exception e) {
            //println("error in close the mongo connection {}", e.getMessage());
        }
    }
    println("end script: vertica_to_kafka")
}
return
System.exit(0)

在MyKafkaStringProducer中,我发现了以下内容:

public synchronized void init() {
    if(this.active) {
        this.initKafkaProducer();
        this.executorService.scheduleWithFixedDelay(this.eventsPublisher, 3L, 3L, TimeUnit.SECONDS);
    }

}

0 个答案:

没有答案