In this tutorial, we will, How can we create and configure Selenium Job in Jenkins and how Jenkins is used for Continuous Integration.
We will see and understand all steps one by one in details.
Create New Job in Jenkins
To create the Project, First, you need to open the Jenkins in your Browser. So open the Jenkins in your browser using – http://localhost:8080/
On this page, you will get the option ‘New Item’. Click on it.
It will render you on the new page, on this page, you will get the many options like ‘Freestyle project’, ‘Maven project’ ..etc . Let’s start with simple thing first and select the first option ‘Freestyle project‘ and enter the Project name ‘TestProject’ inside the item name field and click on ‘OK’ button.
It will render you on the Project Configuration page. Here we can set the desired configuration. We will talk about all in details. First, let’s see the sample configuration screen.
Enter the Description, It’s an optional field. Below we are getting ‘Advance Project Options’, we will talk about these later.
The second option is for ‘Source Code Management ‘, Here we have many ones like CSV, SVN etc. Let’s select ‘None‘ (We will talk about others later).
Later on, we have option ‘Build Triggers’. This will decide when to build trigger or execute over Jenkins. We will talk about it.
Next, We ‘Build’, This option is for, how the Build has to be made. In this click on ‘Add Build Step’ and select the option ‘Execute Windows Batch Command‘, because we are using windows. In this type ‘echo %time%’ (This will tell us the system time). Now click on the ‘Save’ button to save your project.
After saving your project, go to the Jenkin home you will get the Project in Jenkins project.
So we have created our First Jenkin project successfully.
Now to build the Project, You can click on the Project and click on the option ‘Build Now’ (present in the left top menu list). As you have click this option you get the Build History. This history will maintain the list of recently executed build. You can click on the Build (Present under the Build History) and see the result click on the option ‘Console’. Here you will get the build output. As we have passed the current time in command, So for our Test Project Build, it will print the System time when the build was executed. If Build fails then you will get the error in console with the error reason code. Let’s see the console of our Build.
So we have seen, How can we configure the Project in Jenkins.
Now let’s take a step ahead and do some advance modification in Project Configuration. Now suppose we want our project will execute at the certain time interval or at the weekend day or at day end or at the specific time every day. So can we achieve that in Jenkins?
Schedule Job in Jenkins
For this you have to play around option ‘Build Triggers’, You remember last we executed the Project explicitly using ‘Build Now’ option. In Build Trigger, we have many options –
- Build after other projects are built – Suppose Projects are dependent like Project B is Dependent on A. If you check in one and enter the Project Name then Test project will build each time. When the Project A Build. You can do this manually for your practice.
- Poll SCM – Poll SCM means Poll Source Code Management (Option where we have selected ‘None’). Suppose you have checked the option SVN(SubVersion) then you can define the Polling time in this section like Polling in every 5 minutes to SVN and verify that everything is fine and working and report a failure if occurs.
- Build periodically – This will build the project periodically. Like, Suppose you want to build the project in every 5 mins or 1 hour then you can use this option.
Now let’s see, How can we automate this process. Now let’s suppose we want to execute our project in every 5 mins then How can we do this
- First, Open your Project.
- Click on the Option ‘Configure‘, Option present in the Project menu options.
- Click on the option ‘Build Periodically’ and enter the parameter.
Note : This accepts the argument in the specific order like- Minute – Hour – Day of the Month – Month – Day of the Week. So if you providing the argument like if you are providing ‘0-0 2 * * *’ it means o minute 2 Hour any month, any week any day i.e 2 AM at every day. so This will build the project 2AM every day
- Enter the argument in the text box and click at the outside of the box. Jenkin will tell you are you providing the written argument or not. Suppose we are providing 0-0 2 * * * i.e run everyday 2AM then Jenkins will tell us the validity of this.
- As we want to run our project after every five minutes, So we will pass the arguments like – ‘H/5 * * * *’.
- Now click on the ‘Save’ button.
Now, this project will be built in every five minutes. You can check it in your local. So this is Jenkin all about, it will check on the server that everything is woking fine as per the configured configuration.