I am running my jmeter tests using Jenkins and maven-jmeter plugin.
My pom.xml is configured as below.
<testFilesIncluded>
<jMeterTestFile>001-Test1.jmx</jMeterTestFile>
<jMeterTestFile>002-Test2.jmx</jMeterTestFile>
<jMeterTestFile>003-Test3.jmx</jMeterTestFile>
<jMeterTestFile>004-Test4.jmx</jMeterTestFile>
<jMeterTestFile>005-Test5.jmx</jMeterTestFile>
</testFilesIncluded>
Also, using performance plugin in jenkins for reporting.
So if my first test (001-Test1.jmx) fails (assertions fail), i do not want to execute the next test (002-Test2.jmx).
How can i accomplish this ?
Thanks for your help in advance.
I'm not sure if that helps,
but if you used TestNG you could make sure a certain number of test methods have completed and succeeded before running more test methods by setting the dependencies in testng.xml
<test name="My suite">
<groups>
<dependencies>
<group name="c" depends-on="a b" />
<group name="z" depends-on="c" />
</dependencies>
</groups>
</test>
Hope you can make some use of it.
Using ant, you can define different Jmeter tests as separate targets and set up dependencies between them. That's exactly what you need. Remember that maven describes the structure of your project, not the logic of its execution (if-then). But ant does. So, try to switch to ant.
Related
Can someone help me to solve an issue "process leaked file descriptors jenkins"?
I tried whit BUIL_ID = dontkillme but it doesnt work.
Thx
It would help to know more about what you're trying to run but this question came up as a result of troubleshooting an issue I was having so here's how I resolved it. I am using Windows so if you're using something else it may not work for you.
First of all you need to read and understand the Jenkins documentation on the issue: https://jenkins.io/redirect/troubleshooting/process-leaked-file-descriptors
I had to install Ant first since it was not installed.
https://ant.apache.org/bindownload.cgi
The Jenkins documentation gives you an example Ant script:
<exec executable="cscript.exe">
<env key="ANTRUN_TITLE" value="Title for Window" /> <!-- optional -->
<env key="ANTRUN_OUTPUT" value="output.log" /> <!-- optional -->
<arg value="//NoLogo" />
<arg value="antRunAsync.js" /> <!-- this script -->
<arg value="real executable" />
</exec>
You will change the "real executable" to be the executable you are wanting to run.
See that .js file in the 2nd arg value? You will need to create that. There's a link to this on the Jenkins documentation page too. Grab it here: https://wiki.jenkins.io/download/attachments/1835010/antRunAsync.js?version=1&modificationDate=1184046328000&api=v2
I didn't make any edits to the contents, just pasted it right in and saved it as antRunAsync.js
So now you take your Ant example script I posted above and throw that in a text editor, save as build.xml
From this point you should be able to test on the command line by typing ant and pressing enter. Your application should load in a different window.
If you haven't set up Ant in the Jenkins Global Tool Configuration do so now and point it to your Ant install (might have to uncheck the Install checkbox). In the Jenkins project add a build step Invoke Ant. Set that up how you like according to Ant documentation.
Hope this answer helps someone else who has stumbled across this problem and this question.
I have PHP Project, that is hosted on GitHub.
Now, I'd like to configure Jenkins to run unit tests so that:
Whenever developer push/commits code to specific branch, it triggers corresponding PHPUnit build job.
If commit passes the unit tests, the source code is deployed (assuming I already have the required script to deploy).
The question is how to trigger the deployment script when source code passes the unit test (i.e. PHPUnit tests succeed)?
Please suggest to me the way to do that, which plugin I should try to achieve the result?
Thanks!
This is going to be a long post, as there's a lot involved, but it works a treat:
You will need:
Ant
Git Publisher plugin
Ant and phpunit will need to be on your PATH
Step 1: Configure your project
In your Jenkins, configure your project to 'Poll SCM' under the Git option. Leave the 'Schedule' as blank. Under 'branches to build' set that as the branch you want to build your release package from.
Reference:
Step 2: Run ant for every build
Add a build step to 'Invoke Ant'
If you don't use Ant already, create a build.xml file in your project root, add it to Git and have the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<project default="full-build">
<property name="phpunit" value="phpunit"/>
<target name="full-build"
depends="phpunit-unittests,-check-failure"
description="runs the tests"/>
<target name="phpunit-unittests"
unless="phpunit-unittests.done"
description="Run unit tests with PHPUnit">
<exec executable="cmd" failonerror="true" resultproperty="result.phpunit" taskname="phpunit-unittests">
<arg value="/c"/>
<arg value="${phpunit}"/>
<arg value="--configuration"/>
<arg path="${basedir}/phpunit.xml"/>
<arg value="--testsuite=Unit"/>
</exec>
<property name="phpunit-unittests.done" value="true"/>
</target>
<target name="-check-failure">
<fail message="PHPUnit did not finish successfully">
<condition>
<not>
<equals arg1="${result.phpunit}" arg2="0"/>
</not>
</condition>
</fail>
</target>
</project>
That will run all unit tests whenever the Ant task is invoked, which is now set for every time the project is built.
Then, install the Git Publisher tool. Configure as follows:
This creates a new release tag upon a successful build. You will use this later to publish the release to the final location. Note: There are different variables that Git Publisher provides for use, commit hash, user etc so use what you want. I stick to an incremental tag of v1.1.BUILD as that's a bit more standard.
Lastly, you will need to add a Git hook which will trigger a build upon a commit/push from any location.
Navigate to your repository folder and within that the 'hooks' directory.
Create a new file named 'post-receive' (you will see examples in there; overwrite this one). Place the following content in:
#!/bin/bash
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "master" == "$branch" ]; then
curl http://YOUR_JENKINS_URL:8080/git/notifyCommit?url=YOUR_GIT_REPOSITORY_URL
fi
done
That should do the job nicely. I have left out implementation details of how you actually release your project as everyone does this differently. There are options to FTP files to a location, and all sorts. Personally I go into the folder where the application resides and do a checkout of the newly created tag - a one line command. Whatever suits your environment.
Other stuff I've ommitted but you will find useful - the Ant build task can do literally anything - In mine, I run composer to install dependences, run bower, run grunt, do syntax checking, coding standard checking, fire up selenium and run web tests, and a load of other stuff. It's a perfect combination of tools to automate the whole project deployment.
I have a simple question, yet I don't have an answer. Can some one pls help:
What I have is:
ParentDirectory
Child_module1
Child_module2
I'm analyzing using sonar ant.
<property name="sonar.sources" value="/xyz/home/emahaboo/work/abc_project_branch/ParentDirectory"/>
<property name="sonar.binaries" value="/xyz/home/emahaboo/work/abc_project_branch/ParentDirectory"/>
I'm able to connect to the sonar server and get the integration test coverage for 1 module. Like this
<property name="sonar.sources" value="xyz/ParentDirectory/childModule1"/>
<property name="sonar.binaries" value="/xyz/ParentDirectory/childModule1"/>
There are "n" number of modules. I wanted to know how to run the following:
1. Run analysis for more than 1 module. like this
xyz/ParentDirectory/ChildModule1
xyz/ParentDirectory/ChildModule2
2.Run analysis from the ParentDirectory
xyz/ParentDirectory/
Issues I am facing:
For 1: I see SONAR analyses on ChildModule2
For 2: I get this error: Caused by: java.lang.IllegalStateException: Fail to get the canonical path of xyz/ParentDirectory/ / / / / /
Can some one please help?
Really apprecite it
The Sonar documentation describes how multi-module builds are configured in ANT:
Multi-module documentation
It also provides links to two examples:
java-ant-modules-same-structure
java-ant-modules-different-structures
I have an Ant build with a lot of javac tasks.
I want all of them to be executed with the following attributes:
debug = "true" debuglevel = "lines,vars,source"
(by default debugging information is turned off which makes it harder to investigate the console).
Is it possible to provide such attributes in some centralized place which will have influence for all javac tasks in current Ant build? (I don't want duplicating them over all javac tasks...)
You need ant's presetdef
From the example
<presetdef name="my.javac">
<javac debug="${debug}" deprecation="${deprecation}"
srcdir="${src.dir}" destdir="${classes.dir}">
<src path="${gen.dir}"/>
</javac>
</presetdef>
Instead of my.javac, you can put javac.
You can define this in one build file and import every where else.
I want to make a Jenkins job to run an ant task to run all tests in my codebase which are tagged #Ignore because using annotations like #Category(IgnoredTest.class) do not work with our test run parallelization. After a lot of searching it looks undoable, but I still have hope. Help?
JUnit 4.10
I'm not sure what the impediment is with your "test run parallelization", but you might be able to do this with a rule if you're willing to use a custom "ignore" annotation instead of the JUnit one. The reason for that is that JUnit handles #Ignored tests at the Runner level, specifically in the BlockJUnit4ClassRunner.runChild() (by default). If you could find a way to use a custom Runner in Ant, you could come up with one to meet your needs pretty easily, but I don't know if that's easily doable in Ant.
As I first mentioned, though, you can easily use a different annotation and a rule to choose which methods to run. I made up a quick example of such a rule on github, along with a test that uses it. My little example uses a system property for switching, but you can also obviously make it switch on anything you can think of that you can get your hands on here.
You can clone and run this example with:
git clone git#github.com:zzantozz/testbed tmp
cd tmp
mvn test -pl stackoverflow/9611070-toggleable-custom-ignore -q
mvn test -pl stackoverflow/9611070-toggleable-custom-ignore -q -D junit.invertIgnores
The one downside of this approach that I can think of is that your tests won't get properly marked as "ignored" because that's also done by the BlockJUnit4ClassRunner.runChild() method, and if you peek at ParentRunner.runLeaf() (which runChild() delegates to), you'll see that the notifier, which is what you need to report ignored tests, isn't passed down far enough to be used by a Rule. Again, it's something you'd need a custom Runner for.
You could create a special ant target that removes the #Ignore annotation and add an #ignore annotation to any active #Test annotated method
the target would be something like this:
<project name="anyname" default="test" basedir=".">
..
..
<target name="enable-ignored-test" depends="copy-code-to-replace-ignored">
<fileset id="fsTestCase" dir="." includes="**/*Test.java">
</fileset>
<replaceregexp flags="gm">
<regexp pattern="^#Ignore"/>
<substitution expression=""/>
<fileset refid="${fsTestCase}"/>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="#Test"/>
<substitution expression="#Ignore #Test"/>
<fileset refid="${fsTestCase}"/>
</replaceregexp>
</target>
<target name="run-ignored-tests" depends="enable-ignored-test,test" />
..
..
</project>