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
Asked
Active
Viewed 465 times
2 Answers
0
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.

Adam
- 2,214
- 1
- 15
- 26
-
I've created another job in jenkins which kills the current running java process by using its jar name. But the thing is, The jenkins job which is running my java process is getting failed after I kill it by using another job. – krish Dec 28 '16 at 19:11
0
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, e.g.
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();
}
}

Community
- 1
- 1

Stefan Freitag
- 3,578
- 3
- 26
- 33