How to use Ant Script to Start and Stop JMeter test - ant

I'm new to JMeter and Ant and my web searches have not been fruitful so I'm posing a question here: Is it possible to start and stop a JMeter script using Ant?
Here's what I'm trying to do:
I have a JMeter test plan with a loop in it that is to simulate a user (or several users) sitting on a page for an indeterminate amount of time after a page refresh. In JMeter GUI mode, I can schedule the thread group to spin up users at a specified time and continue doing so for a specified duration. I'd ideally run this script for 45 minutes or so, stop the script and analyze the results. I would like to automate the running of this script and Ant seemed like the way to go. I did not see an appropriate property to specify a start time or a duration when running the script. Does such a thing exist? Is there a suitable workaround? Any help that can be offered is greatly appreciated.

There is a JMeter Ant Task available. You can kick off your Test Plan using this Task according to documentation.
For 45 minutes test duration I would go for the following:
<jmeter
jmeterhome="/path/to/your/JMeter/installation"
testplan="/path/to/your/test/plan.jmx"
resultlog="/path/to/your/test/results.jtl">
<property name="duration" value="2700"/>
</jmeter>
And put ${__P(duration,)} into Thread Group Scheduler's "Duration" input field
Once you start Ant JMeter will pick up that "duration" property and ask threads to stop when 2700 seconds (45 minutes) pass. Remember that in case of high number of threads shut down process may not be immediate as JMeter might need some time to gracefully shut down all the test threads.
For detailed explanation on using JMeter Ant Task and few more options of running tests in non-GUI mode see 5 Ways To Launch a JMeter Test without Using the JMeter GUI guide.

From what have you written I think you want to schedule a test from non-gui mode and control the parameters also. I am not sure about ant but we have workaround.
For this you can use JMeter non-gui features
If you want to start a test then you can use
Jmeter.bat/.sh -n -t
You can stop the test using stoptest.bat/.sh and shutdown.bat/.sh at any time (Maybe a wrapper shell/batch script can help you to automate this)
For specifying parameters you can override the existing parameters by specifying them from command line as properties local/global like,
-D[prop_name]=[value] - defines a java system property value
-J[prop name]=[value] - defines a local JMeter property
and use these properties in your test plan so that you can pass values while running the test for a specific amount of time or infinitely and stop the test in between (like you said after 45 min) using stoptest.bat/.sh
Example,
In Thread Group set Number of Threads to ${__property(users,,)} and specify it from command line as,
jmeter -Jusers=50 -n -t Test_Plan.jmx
Remember this local property and not global.
For using properties and non-gui mode you can refer this, Jmeter Manual

Related

how to show quantitative results in Jenkins

Jenkins test results screen shows only pass/failed results.
I would like to show quantitive (number/percentage/time duration etc') results, parsed from logs.
e.g. memory usage, run time of specific methods etc..
What is the best way to do so?
Thanks
good question.
i imagine you're probably looking to extend your Jenkins instance with some plugins that describe more info about the tests you've run. this plugin seems relevant, but requires some experience with JMeter (java-based performance measurment tool) to generate the output that this plugin can then read and display output from a JMeter task that you can run every time your build runs:
https://wiki.jenkins-ci.org/display/JENKINS/Performance+Plugin
the 'readme' in the above plugin details page specifies how to set up a project to run JMeter( see the 'Configuring a project to run jmeter performance test:' near the bottom.
another way to do similar not so immediately tied to a specific jenkins build is to run resource monitors (like Cacti or collectd) on the machines running the tests and analyze those results post-build, but again, outside of the Jenkins context.
HTH.

configure grid extra (groupon) with jenkins in order to run cucumber tests

I'm struggling with something for quite a while and can't find a solution,
I got a test project (cucumber, maven) I configure jenkins to pull the project from github, build and execute the code (selenium test script) on jenkins slave and that works perfect, I added few more slave, tagged them and I'm able to execute the same job parallel(the same test cases on different machines)
my next step is to use grid extra (https://github.com/groupon/Selenium-Grid-Extras) in order to use some cool features like video recording, browser updating, selenium updates etc...
now, I know that in order to use the grid I need to address it via my code and also define the desired capabilities (browser, os etc...).
currently when I'm running the same job twice, my second request will be queued till the first one ends, if I will run the same code from two developers machine it will run at 2 different nodes and the grid can handle both request.
not sure what is wrong with my jenkins configuration or my grid hub configuration, I checked it again and again and all looks good :-)
so guess I'm missing something
any advice/direction/idea will be highly appreciated.
Thanks
Ronen

How to download a log file with Ant until a specific string is found?

I'm trying to delay the execution of an Ant task until a remote log (which I should download every time) contains a specific string.
The operation should happen like this:
Download the log file from the server
Use regex to figure out if the string is there
If the string is not there, repeat from step 1 (or until a timeout is reached)
I don't know how to implement the "repeat" part.
I found that the waitfor task might help here, but it accepts only conditions so I cannot add the first 2 steps as children.
Any suggestions ?
ANT is a build tool, not a continuous integration engine.
For an example of the latter try setting up Jenkins to run your ANT build, using a build trigger plugin. Th URLTrigger plugin can be configured to look for a particular text string.

Jenkins builds all starting late

We've inherited a set of Jenkins builds. They all seem to start 90-100 seconds after the desired time. For example, a build with a schedule of */5 * * * * starts at :01:37, :06.29, :11:43, etc., instead of :00, :05, :10, etc. that I would expect.
There are a few builds set to run at /5, but they are all delayed and anyway only last a few seconds each.
I see a global 'quiet period' setting of 5.
The system as a whole does not seem busy. There are usually idle executors, and often nothing at all is building.
For most of the builds this isn't a concern, but there are a couple that we would like to make as precise as possible.
Is my expectation wrong? Is there a config option I'm missing? I should add that I am new to Jenkins and may be missing something obvious.
Thanks
We did not find the cause of Jenkins jobs starting late. We hacked up a workaround by having Jenkins start a script on the remote server that sleeps until the desired time. This creates a new problem by tying up a Jenkins executor for several minutes, so we have the remote script spawn a wait task and then return to Jenkins immediately. This creates another problem in that the output of the remote script is lost because when it completes it has no connection to Jenkins anymore. We get around that by having the remote script write its results into a tmp file, and returning the results of the previous run.
So we have a seriously hacked-up solution that actually works fine for our purposes.
We updated Jenkins from 1.492 to 1.565 and the problem went away. Jobs now start within a few seconds of the expected time.

How can I configure execution start between dependent jobs?

My Jenkins server is set up with two jobs A and B say.
Job A is triggered from changes in subversion, runs unit tests and if successful, creates a WAR and deploys it to another environment.
If Job A succeeds, then Job B triggers. This job runs tests against the deployed WAR.
The problem is that the deployment process takes a while and the WAR is not ready in time for when Job B starts and tries to use it.
I'm looking for ideas on how to delay Job B until the WAR is up and running.
Is there a way, once Job B is triggered to wait for x seconds? I really don't want to put it into the tests in Job B if I can avoid it.
Thanks
There is definitely a way for a job to wait - just put sleep into the first shell build step. Alternatively, you can set 'Quiet period' - it's in Advanced Project Options when you create a build.
That, however, is a band-aid solution to be employed only if other approaches fail. You may try the following: if there is a way to make the deployment process (that job A triggers) right before it finishes to touch a file that Jenkins has access to, then you can use FSTrigger Plugin. See use case 3 there.
The most reliable way to make this work would be to make job A not complete until the deployment is successful, e.g. by testing for a valid response from the URL of the deployed web app. This blog post describes one way to do that.

Resources