This repository contains a pipeline project that demonstrates the CI/CD (Continuous Integration/Continuous Deployment) process using Jenkins and Docker. The project includes a Jenkinsfile, Dockerfile, and several supporting scripts.
The Jenkinsfile defines the stages of the pipeline, which are as follows:
-
Build: This stage compiles and packages the Java application using Maven. The built artifacts are archived for later use.
-
Test: This stage runs the unit tests for the Java application using Maven and generates test reports using JUnit.
-
Push: This stage pushes the Docker image to a registry using the provided
push.sh
script. The image is tagged and pushed to the registry. -
Deploy: This stage executes the deployment script
deploy.sh
, which can be customized to deploy the application to a remote machine.
The Dockerfile is used to build the Jenkins environment with necessary dependencies. Here's an overview of the steps:
-
The base image is
jenkins/jenkins
. -
Python 3 and Ansible are installed using pip.
-
Docker is installed, including Docker Compose.
-
The Jenkins user is added to the
docker
group to enable Docker commands within Jenkins.
The repository includes several scripts used in the pipeline:
-
jenkins/build/build.sh
: This script copies the built JAR file and builds the Docker image using the provideddocker-compose-build.yml
file. -
jenkins/build/mvn.sh
: This script facilitates Maven execution within a Docker container to build the Java application. -
jenkins/build/docker-compose-build.yml
: This configuration file defines the Docker Compose build process for the Java application. -
jenkins/deploy/deploy.sh
: This script executes deployment-related actions, such as copying authentication credentials and running thepublish
script on a remote machine. -
jenkins/deploy/publish
: This script can be customized to define the deployment steps specific to your environment. -
jenkins/push/push.sh
: This script handles the Docker image pushing process, including tagging and pushing the image to the Docker registry. -
jenkins/test/mvn.sh
: This script enables Maven testing within a Docker container.
To use this pipeline project:
-
Set up a Jenkins server with the required plugins and configurations.
-
Create a new pipeline job in Jenkins and configure it to link to your Git repository.
-
Copy the content of the Jenkinsfile into your pipeline job configuration.
-
Copy the Dockerfile and other scripts to the appropriate locations on your Jenkins server.
-
Customize the scripts as needed for your specific project and environment.
-
Build and run the pipeline job in Jenkins to trigger the pipeline stages.
Make sure to configure any necessary credentials or environment variables for the pipeline stages to work correctly.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to explore and adapt this pipeline project according to your requirements. Happy pipeline building! happy learing