简体   繁体   中英

Set build duration in jenkins

I have java project which I'm currently running it through jenkins. I just want to run the job for 5-10 minutes. Is there anyway that we can set the duration of the jenkins build. Since my java process will keep on running without any end. I just want to end that in a particular amount of time. Is there any way that we can do that? Thanks in advance

You can have Jenkins run a script that sleeps for a certain amount of time, finds the PID of the Java process and then kills it.

Or you can have a JVM parameter that your application knows about, and shutdowns after the time has elapsed.

This sounds like you are trying to abuse Jenkins for some strange thing. I would try to shutdown the application itself after a certain amount of time. Here or here you find information on SO on how to end a Java application after a some time - it basically utilizes an ExecutorService or a TimerTask, eg

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class ExitOn {
  Timer timer = new Timer();

  TimerTask exitApp = new TimerTask() {
    @Override
    public void run() {
      System.exit(0);
    }
  };

  public ExitOn() {
    timer.schedule(exitApp, new  Date(System.currentTimeMillis()+5*1000));//Exits after 5sec of starting the app
    while(true)
      System.out.println("hello");
    }

  public static void main(String[] args) {
    new ExitOn();
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM