I have an ant file with multiple targets (task 1 , task 2, task3..) I want to implement sleep between each target execution. I did that by introducing new target of sleep (it is Perl file execution contains sleep Perl script). Now, I called the target as:
target name="task1" description="XX" depends="sleep"
target name="task2" description="XX" depends="sleep"
When I do this, my sleep target is executed only once. It is not executing for all the targets. Please guide me to introduce sleep between each target.
The simplest way would be to execute a sleep Ant task at the start of each target:
<target name="targetX" description="xxx">
<sleep seconds="2"/>
...
</target>
You might be Suffering from Buffering. You can set $| to 1 if you need unbuffered output.
Your sleep target is executed only once -- and this is the expected behaviour in Ant to avoid duplicate execution.
You can write a BuildListener.
Put Thread.sleep(sleepTime) in targetFinished method.
Related
I have a situation where I want to make the execution of my scripts smarter. I have a set of scripts that execute at a given time, but because sometimes the input files are not posted at the correct times the scripts run into errors and get unexpected results. so one of the solutions I was thinking of is to make the execution of the scripts dependent of each other. Here is what I mean:
script 1 runs at 6 pm
validates that the file is there
if it's there, set a flag
the flag is active so execute script 2 at 9 pm
if it's NOT there, the flag is not set
the flag is not set so script 2 is not executed
Right now script 1 and script 2 are set with the Task Scheduler at those times, I checked the Scheduler for those type of conditions, but didn't find anything.
You can set triggers in Task Scheduler, like when an event happens for basically everything you can see in eventviewer.
I would suggest Write-Eventlog from the script which works on the file, and depending on the result the sched task would get triggerd.
I suggest you to have single script running every N-minutes on single scheduled task via Task Scheduler.
The master script will analyze activities and have all logical conditions those determine when and which external script to run. You can also have flag files.
I'm running two Perl scripts in parallel in Jenkins
some shell commands
perl script 1 &
perl script 2 &
wait
some more shell commands
If one of the perl scripts fail in the middle of the execution , the job waits until the other script runs (as it is executed in parallel in background).
I want the job to stop as soon as one of the script fails and not waste time by completing the execution of other script.
Please help.
You set up a signal handler for SIGCHLD, which is a signal that is always delivered to the parent process when a child exits. I'm not aware of a mechanism to see which child process exited, but you can save the subprocess process identifiers and just kill both of them when you receive SIGCHLD:
some shell commands
perl script 1 &
pid1=$!
perl script 2 &
pid2=$!
trap "kill $pid1 $pid2" CHLD
wait
some more shell commands
The script above has the downside that it will kill the other script regardless of the exit status of the subprocess. You could in the trap, if you want to, add a check for the exit status. The subprocess could e.g. create some temp file if it succeeds and the trap could check if the file exists.
Typically with Jenkins you would have the parallel steps running as separate jobs (or projects as they are sometimes known) rather than steps in a job. This would then allow the steps to run in parallel across different slave machines and it would keep the output for the jobs in a separate place.
You would then have a controlling job running the other parts.
I like the Multijob plugin for this sort of thing.
There are alternatives which may suit better, such as Build Flow Plugin which uses a DSL to describe the jobs you want to run
I am starting a JBoss server in Jenkins as a build action. The next action runs a set of tests. I need to add sleeptime between the two actions. Does anyone know how to do this easily?
It is possible to use sleep step in your Jenkins Pipeline. The step is included in Pipeline: Basic Steps.
Example:
steps {
sleep time: 250, unit: 'MILLISECONDS'
}
You can add sleep command (on Unix) in the test build action before test execution.
If you mean to know how to sleep between those build steps you can use sleep with Execute shell type.
sleep 30s
There is a built-in feature in Jenkins to put a sleep but it is not easy to find it because they call it differently.
On the following screenshot
You can see there is a Quiet period setting in the advanced project options that is "executed" before the current job (project).
If you have 3 jobs you can as well set this setting for jobs 2 and 3 which will make:
job1 -> (sleep -> job2) -> (sleep -> job3)
I just added a Powershell step to run script with Start-Sleep -sec 240
all previous answers are correct, here is more detailed info for linux envirnment.
Search you existing Job Configuration for "Add build step"
Select Execute Shell and then add sleep some_number.
Let's say I have 5 batch files that run sequentially one after another (executed via the Windows task scheduler on a normal Windows XP PC):
Script1.bat
Script2.bat
Script3.bat
Script4.bat
Script5.bat
Suppose one of the scripts fail (an error condition is detected -- details on how this happens is not important for my question here). How do I stop the other scripts from running if they all run within the task scheduler? For example, if Script1.bat fails, I don't want to run Script2-5.bat. If Script3.bat fails, I don't want to run Script4-5.bat, etc.
I thought about writing a flag value to a temporary file that each script would read from. At the beginning of each script (except for the first one), it will check to see if the flag is valid. The first script would clear out this flag at the beginning each time these set of batch files run.
Surely there is a better way to do this or maybe there is a standard for how to handle this type of situation? Thanks!
Write a master.bat file that conditionally calls each of the scripts in sequence. Then schedule the master instead of directly scheduling the 5 scripts.
#echo off
call Script1.bat
if %errorlevel%==0 call Script2.bat
if %errorlevel%==0 call Script3.bat
if %errorlevel%==0 call Script4.bat
if %errorlevel%==0 call Script5.bat
I have a nant script and I see that even if my exec fails, the exit code of NANT is 0 anyway. How do I change NANT exit code?
The exec task has an attribute called "resultproperty", which is there to get the exit code.
Returning a Specific Exit Code from NANT
If the build succeeds NANT will exit with code 0, if the build fails NANT with code 1 and you can use <fail> to force this. NANT gives no other way of controlling the exit code however you could hack it:
<script language="C#">
<code>
<![CDATA[
public static void ScriptMain(Project project)
{
System.Environment.Exit(3);
}
]]>
</code>
</script>
This will end nant immediately, so perhaps you might want to create a target to be run at the very end by putting it into nant.onsuccess.
Why NANT Exit Code is 0 when <exec> Failed?
<exec> fails when the command exits with anything but 0. Normally this causes the whole build to fail in consequence and NANT to exit with code 1, with two exceptions (see 2 and 3). This gives us three possible explanations:
Your command fails but exits with 0 anyway (this is a relatively common behavior). Set the resultproperty attribute and check the property.
failonerror="False" attribute has been set on <exec> or on a higher level (<nant> or <call>). Check the NANT output to see in which order targets are being called or search for failonerror=.
The <exec> is executed as part of target started via the nant.onsuccess resp. nant.onfailure property hook. Check if and where by searching for nant.on.
To say anything more a sample NANT script or perhaps a log file would be useful.