This is an introductory exercise about Continuous Integration. You will work with the Jenkins tool, and will create jobs to compile, package and deploy applications in a staging environment.
You must have an IDE to work on this project. We recommend using the IntelliJ IDEA Community Edition. This IDE has good integration with Maven and JUnit.
During this phase you will install the required software to do the exercise:
Maven will be used to manage a Java application (compilation, testing, deployment). Make sure that you have Maven installed on your local machine. If not:
- Download and extract Maven from the Maven website
- Add your maven_folder/bin to your PATH
Git will be used as our repository. Make sure that you have git installed on your local machine. If not:
- Download and extract git from the Git WebSite
- Add your git_folder/bin to your PATH environment variable
Jenkins is a CI/CI tool. Make sure that you have Jenkins installed on your local machine. If not:
- Download Jenkins from the Jenkins WebSite. Select Generic Java Package (war) for this exercise.
- In Mac computers, Jenkins is installed in the /Applications/Jenkins folder
- Start the Jenkins Server from the command line:
- java -jar jenkins.war
- The command will start a Jetty container. You can access Jenkins from http://localhost:8080
- Follow the instructions to unlock Jenkins
- You don't need to install any plugin right now
- Note that the war file can also be deployed into any JEE container. But for now, let's use this simplified startup process.
- Open Jenkins startup page http://localhost:8080
- Change the admin password. Go to the admin user menu (top-right of the screen) > Configure and change your password
- Go to Manage Jenkins > Manage Plugins option
- Install the GitHub plugin. This plugin integrates Jenkins with Github projects
- Install the Deploy to container Plugin. This plugin allows deploying your app into a JEE server. We will use it during the remaining steps.
- Go to Manage Jenkins > Global Tool Configuration and configure the location of your JDK and Maven. Do not ask Jenkins to install automatically these software units, provide your own location.
- In Mac computers, the JDK installation resides in /Library/Java/JavaVirtualMachines/jdk[version]/Contents/Home/
In this part, you will build a "Hello World" Jenkins Job.
- Open the Jenkins startup page at http://localhost:8080
- Create a new job (new item option)
- Specify a name and choose the freestyle project
- Create a build step to execute a shell command (Unix/Linux/Mac) or batch command (Windows).
- Add some simple command like
echo "Hello World" - Go to the main page and schedule a build
- See if your command executed properly in the console output
In this part, you create your Maven-based Jenkins project. A sample JEE project on GitHub is provided.
- Fork the sample project https://github.com/marciofk/hva-asv-assignment-3.git. Please do not use the original project, fork it and you will have your own copy to play during the exercise!
- Open the Jenkins startup page http://localhost:8080
- Create a new job (new item option)
- Specify a name and choose the freestyle project
- In Source Code management, inform your git repository URL (no credentials needed for this GitHub project), keep using the master branch.
- In Build, select to invoke a top-level Maven target
- Select your maven installation
- Specify the goal
clean package
- Go to the main page and schedule a build
- See if your command executed properly
- Check the console output
- Check if your target outcomes are presented in the job workspace
Now, configure the job to start automatically if the repository changes:
- Go to the job configuration
- In Build Triggers, use the Poll SCM strategy
- Use the crontab syntax (check the syntax on Google)
- Make any change in your project and push it to the repository
- Check if the task started automatically
In this step, you will deploy your application into a Tomcat Staging Server.
- Download and install Tomcat 8
- Change the configuration of Tomcat to run in a different port (e.g. 8090). Note that Jenkins is already running on your local machine at port 8080.
- Go to the tomcat_installation/conf/server.xml and change the port 8080 to 8090
- Change the configuration of tomcat-users.xml and add the following roles and users. For the sake of simplicity let's use the standard tomcat user and password. We are using the role manager-script to allow the deployment using HTTP.
<role rolename="manager-script"/>
<role rolename="tomcat"/>
<user username="tomcat" password="tomcat" roles="tomcat,manager-script"/>
-
Start Tomcat using (In Unix/Linux/Mac computers you will need to grant execution permissions to the bin shell scripts)
-
Open the Jenkins startup page http://localhost:8080
-
Modify your existing job
- In Post-build actions, create a deploy war/ear to a container
- You can use "target/*.war" to specify the file
- Leave the context path empty
- Select "Tomcat 8 container"
- Inform the Tomcat URL (http://localhost:8080) and credentials (use the user tomcat, password tomcat)
-
Go to the main page and schedule a build
-
Check if the build executed properly
-
Test if the application is running
The actual solution is mixing compilation and deploy in the same job, which is not recommended. Create a pipeline composed of two jobs (compilation + deployment).
Hints:
- The easiest way is to configure the deployment job to start right after the compilation job. See the "Build Trigger" called "Build after other projects are built".
- You will need a plugin to copy files from one project to another.
- If you have time take a look at the "Pipeline plugin" for Jenkins
This project is using JaCoCo to generate the coverage report. The report is generated in the target folder, as could be seen in assignment 1. Your task is executing scripts to copy the HTML files to a web server.
Hints:
- For the sake of simplicity, you can publish the HTML in your tomcat running at port 8090 in the folder webapps/root. Static files are visible from the root folder of your tomcat installation.
- You will need a plugin to run "shell scripts"