Execute TestNG Tests in Jenkins

In previous tutorials we have seen executing testng.xml from batch file (.bat) which is an unformatted text file that consists of a series of commands to be executed by the command line interpreter. And we have also seen and executing testng.xml tests from command line,

Before proceeding, create any sample testNGProject, we have already created sample project here and we will execute the same tests here with jenkins help. After creating the sample project, project structure should look like below :

testng jenkins project

Now here we will see how to invoke batch file with Jenkins. Let us follow below steps to invoke .bat file from jenkins :

Step 1:
In Jenkins, you have an option to create 'New Job' Item, Click on it.

Step 2: -
Enter Job name and select "Free-Style Software Project" and then click on 'OK' button.

jenkins job name

Step 3: -
You should see header as 'Advanced Project Options' and with a button 'Advanced'. Now Click on "Advanced" option which will display multiple options.

Step 4: -
Select 'Use custom workspace' and specify your project location (workspace directory) in Directory

Step 5: -
Scroll down to see 'Build' option with 'Add Build Step'. In this drop down select value 'Execute Windows batch command' which Runs a Windows batch script for building the project. The text that we enter in the text box will be executed as a batch file. The script will run with the workspace as the current directory which we have specified in step 4.

jenkins job configure

Step 6: -
Click on Save button. New Job will be created with the configure options that we have defined.

That's It. We have Done.

Now we can execute job file by clicking on the 'Build Now' button which will invoke testng.xml from the batch file. Here the output looks after executing the job:

jenkins testng console output


I want setup my maven project on Jenkins using Root POM
How to take github pom.xml path in Root POM for build???

How can i do it in mac?

Hi All,

I'm following error while running .bat file from Jenkins.

BuildingInstalling JDK jdk-9.0.4-oth-JPR
ERROR: Couldn't find the right download for WINDOWS and i386 combination

Anybody could help me, please.

Thanks in advance.

I am not able to build successful.
Can you please help me with 'Step 5: -' in ubuntu. (Assumption .bat file will not work, need to replace it with .sh )

Hi Sree, you may attach more info about the error so everyone can take a look and figure out what is the issue ;)

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.