Jenkins configuration with Maven and GitHub

Tram Ho

Git is the most widely used modern version control system in the world today, allowing many people to work safely on the same project without obstructing other team members. As part of the team using Git, you and your team members will clone a working copy of the local repository from the Git server. You / the team will add and commit locally developed test scripts and push your changes onto Git

We can make Jenkins get the project source code from a remote Git server, by selecting the option in the source code manager and specifying the path / url where the project source code can be found.

In the example below, we will configure the Git plugin and call testng.xml with maven from jenkins. You may have your scripts / tests selenium added to testng.xml. You can also parameterize your selenium tests using Maven-Testng

Configure Git Plugin in Jenkins

Step 1 : – Manage Plugins -> Filter the list of plugins available with ‘Git Plugin’. Find more details about the Git Plug-in

Step 2 : – Check the Git Plug-in and click the Install button without rebooting

Step 3 : – After the installation is complete, please restart Jenkins using the command in the browser. http: // localhost: 8080 / jenkins / restart

When Jenkins is rebooted, the Git option will be available in source code management when configuring the job

Step 4 : – From Manage Jenkins> Configure System, please provide the correct path for Git to execute.

Step 5 : – In the Git Plug-in, Set git user.name and user.email to match your global configuration options

Now let’s create a Maven Project and build a job from the Git project

Step 1 : – Click New Items -> Enter Project Name -> Select Maven Project -> Click OK

Step 2 : – Job description

Step 3 : – In Source Code manager, Select the ‘Git’ option

Step 4 : – From Build Triggers, If you want Jenkins to monitor the repository and start building whenever any changes are made, we can select the Poll SCM option and enter the syntax of cron .

Builds Periodically: will trigger scheduled builds (If we specify H / 5 * * * *, every 5 minutes) even if you do not change anything. Pull SCM will check the changes before activating any build, if there is a change to the previous version, only the build will be activated.

Both fields follow the cron syntax below, including 5 fields separated by TAB or spaces:

MINUTE (0-59), HOUR (0-23), DAY (1-31), MONTH (1-12), DAY OF THE WEEK (0-7)

  • MINUTE – minutes between (0–59)
  • HOUR – hours between (0–23)
  • DOM – date ranges (1–31)
  • MONTH – month between (1–12)
  • DAY OF THE WEEK – day of the week from (0–7)

For example

  • If you want to run the job every 15 minutes, we should specify the following syntax: H / 5 * * * *
  • If you want to trigger, every 2 hours H * / 2 * * * to distribute the load evenly throughout the hour

In addition to the above, Jenkins also supports convenient tags like @yearly , @annual , @monthly , @weekly , @daily , @midnight and @hourly .

Step 5 : – In Build Settings, to send email notifications, you can check ‘Email Notifications’ and add comma separated addresses.

Step 6 : – In Post Build Actions, you can select steps like Archive artifacts, publish results, etc.

Step 7 : – Click Apply and Save.

Now following the configuration above, the build will activate every 5 minutes. Once the build process is enabled, you can check the console output, which will show you the following image:

And also when you view the build information, it will show you as the image below has information like the following image

Because we are activating the build every 5 minutes, you can see jobs running every 5 minutes (shown in the image below).

Hope this article will help you!

Reference links :

https://www.seleniumeasy.com/jenkins-tutorials/configure-maven-github-jenkins-to-run-testng-xml

Share the news now

Source : Viblo