Installation
Go to https://jenkins.io/ and click on Download/Long-term Support (LTS)/Download Jenkins 2.89.4 for/Windows.
Decompress the file and lauch the installer.
At the end http://localhost:8080/ will open and it will ask for a password.
Go to C:\Program Files (x86)\Jenkins\secrets\initialAdminPassword and use this text.
Click on Install suggested plugins. It will take some time to complete this step (10 min).
After that, create an administrator user. It will be the Jenkins main user.
Creation of a basic job
Click on Create job.
Use myConsoleJob as the name of the job and select Freestyle type.
On the Build section, click on Add build step/Execute Windows batch command.
In Command write “echo Hello World!”.
After that, click on Save and on Build Now.
Once the job is finished, click on #1 and on Console Output.
This way we will see how the command was successfully executed.
Creation of a complex job with JDK, Maven and Git
We are going to use a very basic Maven Java project that contains the next file:
Main.java
package jenkins_maven_demo; public class Main { public static void main(String[] args) { System.out.println("Hello World!"); } }
Configuration of Jenkins
Click on Jenkins (on the navigation bar) to reach the main screen.
Go to Manage Jenkins and then to Global Tool Configuration.
In the JDK section click on Add JDK and deselect Install automatically.
Find on your machine the JDK installation (mine is at C:\Program Files\Java\jdk1.8.0_161) and copy this path in the JAVA_HOME field. In name, type jdk1.8.0_161 (change the version if you have a different one).
In the Git section, in Path to Git executable write C:\Program Files\Git\bin\git.exe and in Name, Git for Windows v2.16.2 (also change this version if you have a different one).
Under Maven, click on Add Maven and deselect Install automatically.
Find tou Maven installation (mine is at C:\apache-maven-3.5.2) and copy this path in the MAVEN_HOME. In name write apache-maven-3.5.2 (again, change this version if you have another one).
Now go to Manage Jenkins/Manage Plugins and find Maven Integration. Mark it and click on Install without restarting (it will take 5 minutes).
Creation of the Maven job
Go to the main screen and create a job (myMavenJob, Maven project type). Click OK.
In Source Code Management, use one Git project you have access to. In my case is: https://github.com/luisgomezcaballero/jenkins-maven-demo.git (you will have to specify your credentials).
In Build, Root POM, write the path to the POM file (in my case is jenkins-maven-demo/pom.xml). In Goals and options write clean package to obtain the jar/war of the Java project.
Click on Save.
Demonstration of the execution
Click on Build Now. It will take some time.
Finally, if we access into the job, we will see in the console a success message.
Furthermore, we will see how the project is packaged in the C:\Program Files (x86)\Jenkins\workspace\myMavenJob\jenkins-maven-demo\target\ path.
Repository
The code of this Maven Java project that has been used to demonstrate the use of Jenkins can be located at https://github.com/luisgomezcaballero/jenkins-maven-demo.
So, what do you think ?