How can I delete the Jenkins builds by its running duration? - jenkins

I have a Jenkins job that sometimes runs for more than 1 hour, sometimes it just runs for few seconds. What I really need are those builds with a duration more than 1 hour.
So I would like to delete those builds with the duration less than 1 hour through e.g. the console.
I've tried a lot to find those builds. Unluckily I couldn't find a way to extract the duration information of the builds.

To get the duration of a build through the console :
build = Jenkins.instance.getItemByFullName('JOB_NAME').getBuildByNumber(BUILD_NUMBER)
println build.getDuration() // in milliseconds
println build.getDurationString() // in hour, minutes, seconds

Related

Circle Ci reduce maximum job duration time

I know there is a 10 min no-output timeout on builds in CircleCi. However we had a dodgy built which for some reason took 5h until it hit a maximum job duration. Is there a way to override this 5h limit to something custom and more sensible for our case like 1h?

Jenkins pipeline with polling triggers multiple times

I've created a number of script syntax Jenkinsfiles with this header:
properties([
pipelineTriggers([
pollSCM('H/5 * * * *')
])
])
They almost always trigger at least twice for every commit. Once within 5 minutes of the commit, and again at +5 minutes from the first build. The builds are shorter than 5 minutes long, meaning the second build triggers after the first build has completed. Jenkins log shows both triggers as being identical, as though the second build is not aware of the first build.
I don't understand how this isn't a larger issue. It makes continuous deployment extremely dangerous. Am I missing something?
First of all, H/5 * * * * -> H means run in the next 5 mins whenever is possible. So if the build was run at 1st minute of the hour, second one may run at 6th-10th min whenever possible (Considers other jobs are running or not). And you didn't mention anything about stopping the concurrent builds also. So it will run as per your configuration.
You can stop building multiple parallel by adding this to your script.
options { disableConcurrentBuilds() }
Hope this helps.

How to schedule jenkins job to run with seconds unit?

Jenkins job trigger cron expression format is ? ? ? ? ?.
It cannot possible set the seconds unit.
But I want schedule seconds unit, like run at everyday 15:20:10.
Because there is a job with cron(0 12 * * *) and every minute job, and these two job must not to run simultaneously.
How can I do that?
Thanks for help.
you can have several options to do that :
use lock plugin to wait until your first job run will finish and only than trigger it.
use the Quiet period option in the Job configuration , add 10 seconds so the job will sleep 10 seconds after it trigger.

Jenkins - JMeter Plugin - How to compare with Previous build in terms of Average Response time in Seconds

I have Scheduled a JMeter Job in Jenkins. My Goal is to compare the result of the current test with previous build's result and provide the status accordingly. I have set the
Unstable % Range as = (-)1 to (+)1
Error % Range as = (-)5 to (+)5
My application's response time always have a variation of 1 second and it is an known factor
Since JMeter is returning Average Response time in milli seconds, Test is marked as failed or unstable as the difference in milli seconds is always high
Instead of comparing the response time in milli seconds, is it possible to convert the response time in Seconds and then perform an build comparison?

Jenkins - How to schedule job every period of days?

I tried to schedule a job run every 28 days but still not have solution yet.
Please help!
Thank!
As the documentation shows, using */X executes in intervals of X.
So, applying this to the "day of month" field, under "Build periodically", you could use the following to build at some consistent point in time once every 28 days:
H H */28 * 2
As an example, the 2 at the end signifies that the build should run on a Tuesday. Otherwise, it will probably build on whatever day of the week the current month started with.
I didn't try it yet so I may be wrong, but how about putting days as hours.
For example, if you want to run Jenkins job every 10 days, you schedule it to run every 240 hours.

Resources