I have setup 2 projects in cc.net for the same web application. A continuous integration project that uses an interval trigger and works fine and a "nightly build" project that uses a cronTrigger. The nightly build essentially builds and deploys the staging/testing server so that people can test without being interrupted with a rebuild every time someone does a commit. What i want to do is have it auto build every morning at 6 am and allow force builds if you want to build any other time. THe cron expression I am using is 0 6 * * *, which i think is correct and seems to set the "next build time" correctly in cc.net. The problem I am encountering is that if i set the build condition to IfModificationExists then if there are no modifications since the last build, it doesn't build at the scheduled time, which is fine, but as soon as someone commits, it builds, which is not what i want, i want it to wait until the next scheduled time. So I tried setting the build condition to ForceBuild which i thought would just make it build at 6 AM every day regardless of whether there were any commits, but it doesn't it seems to make it build constantly over and over again. What am i missing doing wrong?
EDIT
Not sure if this really provides any more usefull info but further to a comment.
<triggers>
<cronTrigger>
<buildCondition>IfModificationExists</buildCondition>
<cronExpression>0 6 * * *</cronExpression>
</cronTrigger>
</triggers>
OR
<triggers>
<cronTrigger>
<buildCondition>ForceBuild</buildCondition>
<cronExpression>0 6 * * *</cronExpression>
</cronTrigger>
</triggers>
If you wants to run every day use
<scheduleTrigger time="06:00" buildCondition="ForceBuild" name="Scheduled"></scheduleTrigger>
Someone, knows how to solve this?? I have similar problem running once a month.
Taken from: http://build.sharpdevelop.net/ccnet/doc/CCNET/Cron%20Trigger.html
A single expression is composed of 5 space-delimited fields :
MINUTES HOURS DAYS MONTHS DAYS-OF-WEEK
Examples:
This trigger will execute 5th day of every month
<triggers>
<cronTrigger>
<cronExpression>0 0 5 * *</cronExpression>
</cronTrigger>
</triggers>
This trigger will execute every day at 5am
<triggers>
<cronTrigger>
<cronExpression>0 5 * * *</cronExpression>
</cronTrigger>
</triggers>
Regards,
Dejan
Related
I created a WebJob as a Triggered job to run on a Schedule. When I uploaded the file it was accepted by the form and I went ahead and clicked RUN because I figured you have to click RUN right after uploading it so that it knows it can go ahead and start running. (I am not sure if I actually have to click RUN, or if I should have just uploaded it and let it be so it should just run on its own according to the CRON Expression provided.)
Well, the job ran as soon as I clicked start and it succeeded which was good news. The issue is, it was supposed to run on its schedule every 4 hours, but never did. It only ran once, which was the time I clicked start.
The CRON Expression I created for it is **0 50 23/4 * * *** which translates to:
At 50 minutes past the hour, every 4 hours, starting at 11:00 PM.
Basically I need the job to run every 4 hours but most importantly at 11:50pm which is why I set that as the schedule. So it should run at 11:50pm, 3:50am, 7:50am, 11:50am, 3:50pm, 7:50pm 11:50pm everyday.
I uploaded the job at about 10pm and it ran at that time because I clicked on RUN but was still expecting it to do its REAL SCHEDULED RUN at 11:50 pm but it never did. The logs show success for that initial run as you can see below.
When I look at the WebJob area in Azure the next day, it shows completed 17 hours ago and only ran once at the time of writing this.
What could be my error here? Is it something wrong with the CRON Expression that I have provided for the job? Before this one I made one that would run every 2 minutes and that one worked perfectly fine, but this one with a more complex CRON Expression seems to give me issue.
What could be my problem here?
I was able to fix this issue scrapping everything and starting over. I was using the incorrect CRON Expression for the trigger times I needed. Also found out that I could just upload the file and not have to click the RUN button since it will just run on its own following the given expression.
so i have around 500 servers for which i wanted to create a script that automatically login and do some trivial activity to create some logs (basically want to send logs through siem tool to check if log sending is working or not) and then automatically logoff from the server.
I am planning that the script can be auto-run on the server every 15 days.
trivial activity can be anything(just want to create logs).
Any help how to achieve that??
EDIT
i was thinking now that stopping and starting a service in server will accomplish my need. Any help on that script. i am actually new in working in linux server. so any help is greatly appriciated.
This can be done by cronjobs, you can simply setup a cronjob to do the task,
0 0 15 1-12 * /path/to/your/script
This Cronjob will run at 00:00 on day-of-month 15 in every month from January through December.
You could use cron jobs.
In the crontab file of every server you need to make an entry of the time when you wanna run the script in your case every 15 days and the location of your script file.
0 0 */15 * * /path/to/script.sh
Mind you the job would run a bit differently, as it would start at the 1st of every month, then on 16th and then finally on 31st if the month has 31 days.
I have a trigger scheduled in my Build config file. It used to work before but I noticed that it's not working since the past few days. Can anyone give a suggestion on this? Where should I check for this? This is my trigger.
<triggers>
<scheduleTrigger time="21:30" buildCondition="ForceBuild" name="Scheduled"></scheduleTrigger>
</triggers>
It is probably because the cruise control project is stopped. If it is stopped the Schedule Trigger would not work, but the intervalTrigger will.
you can add a trigger to force the build on determined time like this.
<triggers>
<intervalTrigger name="Schedule" seconds="1800" />
</triggers>
here it will force on every 30 minutes
As per your condition , IFModification exists , then only the build will be triggered it is not explicit ,better have this done this way else it is unnesary to havea build done without any code change
I searched a lot but i didn't find a solution for my problem.
I use CruiseControl.NET (1.4.4). My project (in ccnet.config) load a repository from a cvs server to a local repository, and launch some executables (msbuild, NUnit...).
I use a trigger (Interval or Schedule Trigger), that launch regularly my project. But if my project has not been modified, it always launch all next tasks. And I would like to avoid it. So i want to launch my project only if a commit has been detected.
Is there any solution for it please?
Thanks
Olivier
Your trigger needs to specify IfModificationExists:
<intervalTrigger
name = "dave"
seconds = "30"
buildCondition = "IfModificationExists" />
Although buildCondition="IfModificationExists" is the default anyway, so as long as its not set to ForceBuild you should be fine.
EDIT:
The URL Trigger might be of some use to you. You can set your svn server to modify a page on commmit and the CC.Net checks the page to see if it has changed, thus not getting all the files.
I start my project as below, which ensures that the tasks get executed only if there are modifications.
Hope this helps,
Anders, Denmark
Edited: My code excerpt didn't make it to the page - I've tried to replace less-than, bigger-than with brackets.
[project name="SpilMerePool" queue="Q2" queuePriority="1"]
[sourcecontrol type="svn"]
[trunkUrl]https://ajf-ser1.ajf.local:8443/svn/SpilMerePool/trunk[/trunkUrl]
[workingDirectory]c:\from_vc\SpilMerePool[/workingDirectory]
[executable]C:\Program Files\VisualSVN Server\bin\svn.exe[/executable]
[username]username[/username]
[password]password[/password]
[/sourcecontrol]
Just use IntervalTrigger, like this:
<triggers>
<intervalTrigger />
</triggers>
You can also add an modificationDelaySeconds, to wait for a number of seconds before starting the build after the last commit.
<modificationDelaySeconds>30</modificationDelaySeconds>
Thank you Anders Juul abd Andy for your quick answers.
By using the intervalTrigger with "IfModificationExists" build condition, the project must be loaded each time (it's logical ^^). But my project size is about 450Mo. So it's a little long.
So my last question is : can we execute all builds and next tasks when a commit command has been detected? (without loading all files, in CruiseControl).
I use TortoiseCVS (version 1.10.10). Maybe we can force CruiseControl project to be lauched after a commit?
I have a file "update.php" which does some MySQL operations. A cron job executes this file every 5 minutes. Unfortunately, I cannot execute the cron job more often.
So I had the idea that I could add ...
<html>
<head>
<meta http-equiv="refresh" content="2; URL=<?php echo $_SERVER['SCRIPT_NAME']; ?>" />
</head>
<body></body>
</html>
... to the page "update.php". Will cron execute the file in a way that the page will refresh automatically? Or will that not happen because there is no client with a browser?
If it the meta refresh has no effect, is there any other possibility to achieve the refreshing of the page?
Thanks in advance!
I'm afraid that won't work, because it's a browser feature to refresh the page.
Question: Why can't you set the cron job to run more frequently that every 5 minutes?
If there is no other option then you could create you're own daemon to do the job more frequently.
e.g.
Your php script could:
Run
Wait 60 seconds
Run
( Wait; Run; two more times)
exit
For example: (By variation of sshow's code)
<?php
$secs = 60;
ignore_user_abort(true);
set_time_limit(0);
dostuff();
sleep($secs);
dostuff();
sleep($secs);
dostuff();
sleep($secs);
dostuff();
sleep($secs);
dostuff();
?>
This version of the script will remain resident for four minutes, and execute the code 4 times which would be equivalent to running every minute, if this script is run by cron every 5 minutes.
There seems some confusion about what a cronjob is, and how it is run.
cron is a daemon, which sits in the background, and run tasks through the shell at a schedule specified in crontabs.
Each user has a crontab, and there is a system crontab.
Each user's crontab can specify jobs which are run as that user.
For example:
# run five minutes after midnight, every day
5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
# run at 2:15pm on the first of every month -- output mailed to paul
15 14 1 * * $HOME/bin/monthly
# run at 10 pm on weekdays, annoy Joe
0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
5 4 * * sun echo "run at 5 after 4 every sunday"
So to run every five minutes:
*/5 * * * * echo "This will be run every five minutes"
Or to run every minute:
* * * * * echo "This will be run every minute"
The output from the commands are emailed to the owner of the crontab (or as specified by MAILTO).
This means if you run something every minute it will email you every minute, unless you ensure all normal output is suppressed or redirected.
The commands are run as the user who owns the crontab, which contrasts with the scripts run by the web-server, which are run as the 'nobody' user (or similar - whatever the web-server is configured to run as).
This can make life more complicated if the cronjob is writing to files which are supposed to be accessed by the scripts run by the web-server. Basically you have to ensure that the permissions remain correct.
Now, I'm not sure that this is the system you are refering to. If you mean something else by cronjob then the above might not apply.
If you want to do something that your current host is not letting you do, then rather than hacking around the restriction, you might what to look at switching hosting provider?
An alternative is to put the script in you're normal scripts location, and have some external scheduler run wget against it at whatever frequency you like.
Another alternative is on-demand updating of the form of vartec's suggestion. However that may not solve your problems.
I'm pretty sure you can achieve it by doing this:
<?php
$secs = 120;
ignore_user_abort(true);
set_time_limit(0);
while (true)
{
// do something
// Sleep for some time
sleep($secs);
}
?>
Edit
You will have to execute it once after every server restart unless you do it like Douglas describes.
Update
Keep Douglas Leeder's answer in mind, and then take a look at this:
http://www.php.net/manual/en/function.ignore-user-abort.php
I'd say don't try to do this with php, change your crontab. If you need your application to do a cronjob every minute and your hosting doesn't provide this option, you have most likely outgrown your hosting. Get yourself a VPS hosting for 20$ a month (Slicehost, Servergrove).
Update: Editted based on new information.
Meta refresh won't work because cronjob.de will be using an automated system that doesn't actually read the contents of the page. No browser, so nothing to see the meta refresh.
You have a couple options. They vary in greater or lesser horribleness.
The best option is to change webhosts. A good webhost will have full support for cron. But if you need to touch cron, honestly, you should probably be on a VPS host anyways. A lot of hosts will object to a cron task running every minute unless the task is just updating something really quickly and exits. But VPS hosts won't usually care. Slicehost offers VPS servers for as little as $20/month. Not recommended for people who've never had root access before.
The only option you've got that will work with cronjob.de's 5 minute limitation is to build a loop that will run an iteration, sleep, run another iteration, and repeat however many times you need before the end of the 5 minutes. However, there are two major problems with this approach. First, if you have a request that lasts 4 minutes, there's a distinct possibility that your webhost might kill the request before it finishes. Second, if the webserver isn't configured just right, such a request might block other requests, preventing legitimate users from accessing your site — they would queue up, and be waiting for the cronjob.de request to finish before their requests could be completed. And since that request will take 4-5 minutes to finish, before being repeated a minute later, they might only be able to access your site once every 5 minutes. I'm guessing this is undesirable. Unfortunately, the only way to know if you'll run afoul of either of these problems is to ask your webhost. I don't recommend trying it before asking, because they may not appreciate it if it goes unexpectedly bad and starts affecting their other customers on the server.
If you're lucky, they may even be willing to set up a cron job for you.
You can use PHP to call the script...
<?php
$script='/path/to/my/php/script.php';
ignore_user_abort(1);
set_time_limit(0);
$php=exec('which php');
while (1) {
if (file_exists($script)) { exec($php.' '.$script); }
else { file_get_contents($script); }
sleep(2);
}
?>
The file you give $script needs to exist, otherwise it thinks it's a URL.
It should do the trick.
What you are trying to do it implies user interaction, so what if no client enters into your "page"?
For example Servlets and EJB containers can do it programmatically at container startup what you need, so I suppose that for PHP the only way to accomplish "automatically" cronlike jobs is to make some changes in your Apache source code, obviously only if you are using an housing server.
A more praticable option not contempling code changes could be some cron script calling directly your page (wget,netcat,etc...) launched during your web server startup