How to setup jenkins job to only run biweekly at 8 AM in the morning.
Considering only the working days, Monday through Friday.
Basically running the build every second Friday.
You can use the following cron expression
0 8 8-14,22-28 * 5
The format explained looks as:
{Minute} {Hour} {DayOfMonth} {Month} {DayofWeek}
You might also want to check out Continuous Integration 101: How to Run JMeter With Jenkins for more information regarding how to set up Jenkins for JMeter tests execution.
This doesn't work, refer issue JENKINS-19756
However, a workaround that doesn't look good but works, check this answer.
Another workaround, that looks fine but works little erratically:
*0 7 1-7,15-21,29-31 * 1*
"all Mondays in 1st, 3rd and 5th week"
(error in this one: if there's a 5th week, it works its next week as well as its the first week of next month)
Related
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
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.
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.
I want to have a trigger to see if there are any changes in the SVN every night from Monday to Friday at 22:00. I understand that I must put the following syntax "H 22 ** 1-5" is this correct?
At the root of this I have a question:
The company is in Spain, then what time is 22:00 Spanish or American?
Thank you very much and best regards.
You can set your timezone by logging into your instance and then going to JENKINS_URL/configure (Global properties).
In some versions of crontab you can set the time zone for when the job should run like:
TZ=GMT
30 11 * * *
This would run at 11:30am GMT every day, even if the server was in some other time zone.
Even though Jenkins scheduling is based on cron, it doesn't seem to have this specific syntax. Is there some other way to do this in Jenkins?
Thanks
As Michael mentioned in his answer, this functionality was added. Here's an example:
TZ=Europe/Kiev
0 1 * * 5
That would run at 1:00 AM Ukraine time, once a week on Friday.
To get the names of time zones to use, you can use the column marked "TZ database name" in https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
Looks like they added this in 2.60.2.
There's no way to do this in Jenkins. You could trigger the builds by calling a URL from cron though.
Edit: This has since been added; see the other answers.