In this Jenkins tutorial we will learn how to install Jenkis Continuous Integration System and configure it to run a basic Maven 3 project.
Jenkins, formerly known as Hudson, is a quick to use continuous integration system, which can be used to automate the built of your projects at a scheduled time or when a trigger is raised (e.g. a CVS commit) or simply when the user requests it. The automated, continuous build can help a lot in increasing the productivity and reducing conflicts.
Besides this, Jenkis can also monitor the execution of external jobs, such as cron jobs and procmail jobs, even those that are run on a remote machine. Let’s get started by downloading Jenkis Generic Java Package Web archive from http://jenkins-ci.org/
Installing Jenkins
You have two options to install the Jenkins Web application Archive:
1) Run it as a Java application by executing:
$ java -jar jenkins.war
The above command will start a Jetty Web Server where Jenkins is deployed. The default port of the service is 8080 (This can be changed passing the –httpPort=$HTTP_PORT parameter to the java interpeter):
2) Deploy the war archive into your WildFly/Tomcat deployments folder with no other configuration required.
For example, if you were to deploy in on WildFly:
$ cp jenkins.war $JBOSS_HOME/standalone/deployments
The installation was a breeze so we can get into the configuration of Jenkins.
You can log into the Jenkins console by pointing your browser at http://localhost:8080
For application server installation, include the Web context information: http://localhost:8080/jenkins
Unlocking Jenkins
The first thing needed to get started is unlocking Jenkins. This requires entering an initial administrator password which is printed on your filesystem and on the application server console too (if you are installing jenkins on the application server):
Type the temporary administrator password.
Jenkins configuration is stored, by default, in your $HOME/.jenkins folder. If you have formerly installed jenkins on your machine you should remove the .jenkins folder so that you can re-install again it.
Next, you will be requested to register for an administration user so fill up the following UI:
What is Jenkins default user? Out of the box there is no pre-defined user for jenkins. You can however (not recommended!) disable the need for logging in by setting <useSecurity>false</useSecurity> in $HOME/.jenkins/config.xml
Basic Jenkins configuration
From the Home page, click on the “Manage Jenkins” link:
From there, you can access to a wide set of options which will let you configure (and update too using plugins) your Jenkins configurations. As first step, we will need to enter the location for our JDK installation and our Maven home. Click on the Global Tool Configuration link:
You will be taken to the Configuration panel. From there, you can configure the JDK Home and the Maven Home to be used.
In order to configure the JDK and Maven click on their buttons. If you have already available an installation of it simply uncheck the “Install automatically” option and enter your JAVA_HOME and Maven Home:
Installing Maven Integration plugin (optional)
Fine. You have a basic Jenkins configuration which is enough to run your first Job. Although not mandatory we will show how to install the Maven, which will make faster and simpler building up Maven projects.
From the Home page of Jenkins select Manage Plugins:
Click on the Available Tab and search for Maven to find quickly your plugin. Check the Maven Integration Plugin:
Now restart Jenkins and you are done with Plugin configuration!
Are you facing javax.net.ssl.SSLHandshakeException when trying to retrieve Jenkins plugins? Check this tutorial to learn how to solve it quickly! Solving Jenkins SSLHandshakeException
Done with permissions now let’s build our first Job which will automate the built of a Maven project.
We will test the build process against the quickstart archetype, which can be installed in a matter of minutes by typing in a terminal window:
mvn archetype:generate -DgroupId=com.sample -DartifactId=webapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
This archetype contains just a Java class and a Junit test case. Just add some logging in the AppTest.java if you want to trace the single steps of your test case. Next, from the left menu select “New Item“, enter a Name for it and select “Maven Project“:
In the Job GUI you can leave the default settings (which don’t handle Source Code Management). Scroll to the Build section and specify the Maven goals that will be used: in our case we will choose “clean install” which will clean,package and install the application on your local repository.
Now let’s run the first Job from the Job Panel by clicking on the “Build Now” button. The Maven build system will kicking taking a little to complete. Once done, you will find in the Build History of your Job the outcome of your build. (A sunshine icon means that the process completed successfully).
You can further inspect on the Build process by clicking on the link and following the Console Output link in the next page.
That’s all for now. In the next tutorial we will improve our skills by gathering sources from a common Repository and start our Jobs using a time schedule. Stay tuned!