Jenkins

Jenkins - Setup Build Jobs

Jenkins - Setup Build Jobs

For this activity, we will build a simple job in Jenkins that picks up a HelloWorld application, builds it, and runs it. Learn each step in this Jenkins tutorial:

Step 1 – Click on ‘New Item’ on the Jenkins dashboard.


Step 2 − On the next screen, enter the ‘Item name’, Choose the ‘Freestyle project option’


Step 3 – The below screen will follow in which the job details can be specified.

Step 4 − We must indicate the location of the files that must be built. In this example, we will assume that a local git repository (E: Program) with a 'HelloWorld.java' file has been set up. As a result, scroll down and select Git, then input the URL of the local git repository.

Please keep in mind that if your repository is hosted on Github, you can also provide the URL of that repository here. In addition, you must click the Add button for the credentials to add a user name and password to the github repository so that the code may be retrieved from the remote repository.

Step 5 – Go to ‘Build section’ and click on ‘Add build step’ → Execute the Windows batch command.


Step 6 – Click on the ‘Save’ button after entering the following commands in the command window.

Javac HelloWorld.java

Java HelloWorld


Step 7 − After you've saved the job, you can verify if you've defined it correctly by clicking the ‘Build Now’ button.


Step 8 – The build will run after it is scheduled. The below ‘Build history’ section shows that a build is currently in progress.

Step 9 − When the build is finished, a build status will show whether or not the build was successful. In our scenario, the following build was completed. To view the build specifics, click on #1 in the Build history.

Step 10 – The build details can be viewed by clicking on the ‘Console Output link’.




Aside from the processes outlined above, several methods exist to establish a build job; the possibilities available are numerous, making Jenkins such an excellent continuous deployment solution.

Jenkins - Unit Testing


Jenkins includes excellent Junit capabilities and a slew of plugins for unit testing in other technologies, such as MSTest for.Net Unit tests. 





An example of a Junit Test in Jenkins which will consider

  • A Junit based simple HelloWorldTest class.
  • To build the class, Jenkins has an inbuilt Ant tool.

Step 1 − Go to the Jenkins dashboard and select the Configure option for the existing HelloWorld project.


Step 2 − To Add a Build step, browse the section and choose the option for invoking Ant.


Step 3 − Click on the ’Advanced button’.


Step 4 − Enter the location of the build.xml file in the build file section.


Step 5 − Next, click the Add post-build option button and select "Publish Junit test result report."


Step 6 − Enter the location as stated below in the Test reports XMLs. Ascertain that Reports is a folder in the HelloWorld project workspace. The "*.XML" basically tells Jenkins to pick up the result XML files generated by the Junit test cases. These xml files are then transformed into reports that can be examined at a later time.

When you're finished, click the Save button at the bottom.


Step 7 − After saving, select the Build Now option.

When the build is finished, a build status will show whether or not the build was successful. There is now a new section in the Build output information called Test Result. As an example, in our scenario, we entered a negative Test case so that the outcome would fail.


More information can be found in the Console output. What's more, if you click on Test Result, you'll be sent to a drill-down of the Test results.