I am using Jenkins to build an rpm for some custom software.

During the build there must be a race condition that only seems to appear when building the RPM, which results in the job finishing successfully, but the software not being built correctly.

The most obvious way to tell the build is a false positive is to check how quickly the build stage finished.

During an actually successful run, the build stage will take approximately an hour. When a false positive occurs it will finish in less than 25 minutes.

The end goal of course is to fix the race condition, but preventing the pipeline from creating a bad RPM and saying the pipeline was successful in the mean time would be a great help.

1 Answer 1


In Jenkins scripted pipelines you could do something like this:

node() {

   Date startTime = new Date()

   long currentTimeMilli = startTime.getTime()

   long hourMilli = currentTimeMilli + 3600000

   Date cutoffTime = new Date(hourMilli)

   // Call the "build" function

   Date currentTime = new Date()

   if (currentTime.before(cutoffTime)) {
       // Call the "build" function again

  • Wouldn't you need to update after the build function, but before the if statement so that it's comparing the actual current time to cutoff time instead of the current time established at the beginning? I think how it is written, the if statement will always be true.
    – Natolio
    Aug 18, 2022 at 16:44
  • That does look like it's the case, but otherwise your answer worked perfectly for me. If you can update the answer so that there is a new time being compared to cutoff time, I will mark it correct.
    – Natolio
    Aug 18, 2022 at 18:18
  • @Natolio good catch, will update soon
    – Levi
    Aug 18, 2022 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.