This repository contains a demo project created as part of my DevOps studies in the TechWorld with Nana – DevOps Bootcamp.
https://www.techworld-with-nana.com/devops-bootcamp
Demo Project: Create a CI Pipeline with Jenkinsfile (Freestyle, Pipeline, Multibranch Pipeline)
Technologies used: Jenkins, Docker, Linux, Git, Java, Maven
Project Description:
CI Pipeline for a Java Maven application to build and push to the repository
- Install Build Tools (Maven, Node) in Jenkins
- Make Docker available on Jenkins server
- Create Jenkins credentials for a git repository
- Create different Jenkins job types (Freestyle, Pipeline, Multibranch pipeline) for the Java Maven project with Jenkinsfile to:
- a. Connect to the application’s git repository
- b. Build Jar
- c. Build Docker Image
- d. Push to private DockerHub repository
Before starting, complete all steps to install Jenkins on DigitalOcean:
Navigate to Manage Jenkins > Tools > Maven installations
Click Add Maven and fill in:
| Field | Value |
|---|---|
| Name | maven-3.9 |
Click Save.
Enter the Jenkins Docker container as the root user:
docker exec -u 0 -it <container_id> bashUpdate packages and install curl:
apt update
apt install -y curlDownload and run the NodeSource setup script, then install Node.js:
curl -sL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
bash nodesource_setup.sh
apt install -y nodejsVerify the installation:
node -v # should print v20.x.x
npm -v # should print a version number- Navigate to Manage Jenkins > Plugins > Available plugins
- Search for
Pipeline Stage View, select it, and click Install - Check Restart Jenkins when installation is complete and no jobs are running
If Jenkins does not restart automatically, start it manually:
docker ps -a
docker start <container_id>- Navigate to Manage Jenkins > Plugins > Installed plugins to confirm the plugin is active.
Why? Jenkins needs access to the host Docker daemon so it can build and push images as part of the pipeline.
docker ps
docker stop <container_id>docker run -p 8080:8080 -p 5000:5000 -d \
-v jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkins/jenkins:ltsdocker ps
docker exec -it -u 0 <container_id> bashRun the official Docker install script:
curl https://get.docker.com/ > dockerinstall && chmod 755 dockerinstall && ./dockerinstallchmod 666 /var/run/docker.sockexit
docker exec -it <container_id> bash
docker pull redis # should succeed if Docker access is working- Navigate to Manage Jenkins > Credentials > System > Global credentials
- Click Add Credentials and fill in:
| Field | Value |
|---|---|
| Kind | Username with password |
| Username | <Your GitHub username> |
| Password | <Your GitHub password> |
| Treat username as secret | Yes |
| ID | github |
- Click Create.
- Log in to Docker Hub
- Click Create Repository and fill in:
| Field | Value |
|---|---|
| Name | app |
| Visibility | Private |
- Click Create.
- Navigate to Manage Jenkins > Credentials > System > Global credentials
- Click Add Credentials and fill in:
| Field | Value |
|---|---|
| Kind | Username with password |
| Username | <Your Docker Hub username> |
| Password | <Your Docker Hub password> |
| Treat username as secret | Yes |
| ID | docker |
- Click Create.
- From the dashboard, click New Item (or Create a job)
- Name:
freestyle - Type: Freestyle project
- Click OK
Under Source Code Management, select Git and fill in:
| Field | Value |
|---|---|
| Repository URL | https://github.com/explicit-logic/jenkins-module-8.2 |
| Credentials | github |
| Branches to build | */freestyle |
Under Build Environment, check Use secret text(s) or file(s), then click Add > Username and Password (separated):
| Field | Value |
|---|---|
| Username Variable | USERNAME |
| Password Variable | PASSWORD |
| Credentials | docker |
Click Add build step > Invoke top-level Maven targets:
| Field | Value |
|---|---|
| Maven Version | maven-3.9 |
| Goals | test |
| POM | app/pom.xml |
Click Add build step > Invoke top-level Maven targets again:
| Field | Value |
|---|---|
| Maven Version | maven-3.9 |
| Goals | package |
| POM | app/pom.xml |
Click Add build step > Execute Shell and enter:
cd app
docker build -t <docker_username>/app:freestyle .
echo $PASSWORD | docker login -u $USERNAME --password-stdin
docker push <docker_username>/app:freestyleReplace
<docker_username>with your Docker Hub username.
Click Build Now and monitor the console output.
- From the dashboard, click New Item
- Name:
pipeline - Type: Pipeline
- Click OK
Scroll to the Pipeline section and fill in:
| Field | Value |
|---|---|
| Definition | Pipeline script from SCM |
| SCM | Git |
| Repository URL | https://github.com/explicit-logic/jenkins-module-8.2 |
| Credentials | github |
| Branches to build | */pipeline |
Jenkins will look for a Jenkinsfile at the root of the branch automatically.
Click Build with Parameters and fill in:
| Parameter | Value |
|---|---|
DOCKER_REPO |
<docker_username>/app:pipeline |
- From the dashboard, click New Item
- Name:
multibranch - Type: Multibranch Pipeline
- Click OK
Under Branch Sources, click Add source > Git and fill in:
| Field | Value |
|---|---|
| Project Repository | https://github.com/explicit-logic/jenkins-module-8.2 |
| Credentials | github |
Click Save. Jenkins will automatically scan the repository and create jobs for branches that contain a Jenkinsfile.
Click Build with Parameters and fill in:
| Parameter | Value |
|---|---|
DOCKER_REPO |
<docker_username>/app |
Notes:
- The Docker image tag is derived from the branch name (e.g.,
main,pipeline).- The test phase runs only on the
mainbranch.






