The repository contains a project carried out as part of learning DevOps technologies.
- GitHub 🐙
- Jenkins 🤖
- Maven 📦
- Java ☕
- Make sure you have JDK installed on your computer (required version: 11, 17 or 21). On Windows 10, you can use the following commands on admin account:
winget search jdk
,winget install Oracle.JDK.21
- Download and install Jenkins. For a detailed guide on the installation process, you can refer to this video.
- After a successful installation, Jenkins runs by default on
http://localhost:8080/
(the port can be changed in thejenkins.xml
file located in the installation directory). To complete the installation process, navigate to the locationC:\ProgramData\Jenkins\.jenkins\secrets\initialAdminPassword
and copy the secret hidden in the file. Paste it into the form. - Complete the installation by installing the suggested plugins and creating an admin account.
Using the Public Over SSH Plugin in Jenkins
In my Jenkins configuration, I use the Public Over SSH plugin to automate remote deployments and run commands on external servers securely. This plugin allows Jenkins to connect to remote machines via SSH using public-private key authentication, ensuring a safe and efficient process for managing tasks like application deployments and system maintenance.
Publish Over SSH configuration
- Install Publish Over SSH plugin.
- Go to
Jenkins > Manage Jenkins > System
. - Scroll down to the end of the page to the Publish Over SSH section and add new server:
SSH Servers > Add
. - Give the
name
,hostname
andusername
obligatory. - Click
Apply > Save
.
Creating a New Project in Jenkins
- After configuring the Publish Over SSH connection, create a new project by navigating to
Jenkins > New Item
. - Ensure that you add the
pom.xml
file to your remote repository on GitHub. This file should contain the necessary configuration for your Maven project. - Provide the URL of the remote repository.
- Specify the branch to pull in Jenkins. By default, Jenkins may show the
master
branch, but the default branch on GitHub ismain
. - Set the appropriate Maven version and goals.
- Click
Apply
, thenSave
. - On the project page, click
Build Now
. - If you encounter any issues, check the
Console Logs
in the project directory on Jenkins for more information.
- Open the command prompt (cmd).
- Enter the following command:
where git
- Copy the resulting path to the Git executable, e.g.:
C:\Program Files\Git\cmd\git.exe
. - In Jenkins, navigate to Manage Jenkins > Global Tool Configuration.
- In the Git section, click Git installations > Add Git:
- In the Path to Git executable field, paste the copied path.
- Click Apply and Save.
- Navigate to the desired Jenkins job (e.g., Jenkins > FIRST_DEVOPS_PROJECT).
- Click Configure.
- In the Source Code Management section, select Git.
- In the Repository URL field, enter your GitHub repository URL, e.g.:
https://github.com/WiolaWysopal/JenkinsGitHubCI.git
.
- In Jenkins, go to:
Manage Jenkins > Credentials
or directly via:
http://localhost:8080/manage/credentials/
. - In the Stores scoped to Jenkins section, select:
System > Global credentials (unrestricted). - Click + Add Credentials.
- Fill in the following fields:
- Kind: Username with password.
- Username: Your GitHub username (or a personal access token if applicable).
- Password: Your GitHub password (or the personal access token).
- ID: Optional (you can specify a unique identifier for these credentials, e.g.,
WiolaDevOps
).
- Save the changes.
- Navigate to the Jenkins job (e.g., FIRST_DEVOPS_PROJECT > Configure).
- In the Git > Credentials section, select the previously created credentials.
- Expand the Advanced section and fill in the following fields:
- Name: The repository name (e.g.,
origin
). - Refspec: If you want to fetch only a specific branch, e.g.,
main
, use:
+refs/heads/main:refs/remotes/origin/main
.
- Name: The repository name (e.g.,
- Open your Jenkins job (e.g., FIRST_DEVOPS_PROJECT).
- Click Build Now.
- Check the console logs:
FIRST_DEVOPS_PROJECT > Build History > Click the current build > Console Output.- A successful configuration will show the following message:
BUILD SUCCESS Finished: SUCCESS
- Configuration issues will appear as error messages in the logs.
- A successful configuration will show the following message:
After properly setting up Jenkins and connecting it to GitHub, you can use this integration for various purposes. Here are some examples:
- Configure a webhook in GitHub to send
push
events to Jenkins. - In Jenkins, set the trigger in the Build Triggers section to
GitHub hook trigger for GITScm polling
. - On every
push
, Jenkins will automatically trigger the job that can, for example, build the application and create a.jar
or.war
file.
- After each application build, Jenkins can run unit tests using tools like Maven or Gradle.
- Configure the Build section in the project to run a command like:
mvn clean test
- Test reports will be saved in Jenkins and visible in the Test Results section.
- Connect Jenkins with Docker and Kubernetes to automate application deployments.
- Example process:
- Jenkins builds the application and creates a Docker image.
- The Docker image is pushed to a registry (e.g., Docker Hub).
- Jenkins runs a script that deploys the application on a Kubernetes cluster.
- Configure Jenkins so that after each
push
, the code is analyzed by SonarQube. - In the Build section, add a step to run the analysis, such as:
mvn sonar:sonar
- The code quality analysis results will be available in the SonarQube dashboard.
- Jenkins can generate and store reports from building the application, tests, or deployments.
- In the Post-build Actions section, add a step to save artifacts or reports:
target/*.jar
- You can configure Jenkins to automatically increment the application version on every build.
- In the Build section, use a Bash script or a tool like Maven to automatically modify the version number in the
pom.xml
file.
- Set up notifications to Slack, email, or another tool to receive information about task results.
- In the Post-build Actions section, add a step to configure, for example, an email with the build results.
Maven support has been added to the project, which enables easy dependency management and automation of the build process. With the integration with Jenkins, the configuration of pom.xml allows for:
Automatic installation of dependencies – e.g., JUnit libraries for unit tests. Build process – Jenkins runs mvn clean install, which compiles the application and generates output files. Automatic test execution – tests defined in the AppTest.java file are run during every build. Test results are reported in the Jenkins interface. With these functionalities, the project demonstrates a basic CI/CD cycle:
Building the application. Testing the code. Reporting results. The Maven configuration is a key element of this process and highlights its practical application in real-world DevOps environments.