MF05-PRA05-MarcFernandez-JenkinsPipeline#75
Open
marcius02 wants to merge 2 commits intoAlbertProfe:masterfrom
Open
MF05-PRA05-MarcFernandez-JenkinsPipeline#75marcius02 wants to merge 2 commits intoAlbertProfe:masterfrom
marcius02 wants to merge 2 commits intoAlbertProfe:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MF05-PRA05: Jenkins CI/CD Pipeline for Spring Boot Application
CIFO La Violeta - DevOps IFCT0116-24 MF05
This practical exercise will guide you through setting up a Jenkins CI/CD pipeline for a Spring Boot project, including Docker integration.
Tasks
1. Pull Jenkins Docker Image
Pull the official Jenkins Docker image from DockerHub:
2. Build and Run Jenkins Container
Create and run a Jenkins container with privileges:
To pause the container:
To resume:
3. Configure Jenkins Account
Access Jenkins at
http://localhost:8081and follow the setup wizard. Retrieve the initial admin password from the Docker logs:Create an admin account during the setup process.
3.1 Install Docker inside Jenkins: bash from host
Here's a summary of the steps to install Docker in a Jenkins container:
On the Linux host:
sudo docker exec -it --user root jenkins bashThis command accesses the Jenkins container's bash console.
Inside the Jenkins container:
This downloads and runs the Docker installation script.

Still inside the Jenkins container:
This adds the Jenkins user to the Docker group.

If permission issues persist, inside the Jenkins container:
This changes the permissions of the Docker socket.

Back on the Linux host:
This restarts the Jenkins container to apply the changes.
Note that steps 2-4 are executed within the Jenkins container's bash, while steps 1 and 5 are performed on the Linux host machine.
4. Install Basic Plugins
In Jenkins, go to "Manage Jenkins" > "Manage Plugins" and install these plugins:
Plugins that are already installed: Git Client, Pipeline and Pipeline: Graph View.
Available plugins to install:
4.1 Configure tools
JDK
Git
Maven
5. Create a Pipeline for Spring Boot Project
Create a new pipeline job in Jenkins:
pipeline { agent any environment { DOCKERHUB_CREDENTIALS = credentials('dockerhub_id') IMAGE_NAME = 'marcius02/bookspageable' IMAGE_TAG = "${BUILD_NUMBER}" } tools { maven 'M3' jdk 'JDK21' } stages { stage('Checkout') { steps { git 'https://github.com/AlbertProfe/BooksPageable.git' } } stage('Build') { steps { sh 'mvn clean package' } } stage('Archive') { steps { archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true } } stage('Build Docker Image') { steps { script { // Build the Docker image and tag it with both BUILD_NUMBER and latest sh "docker build -t ${IMAGE_NAME}:${IMAGE_TAG} -t ${IMAGE_NAME}:latest ." } } } stage('Push to DockerHub') { steps { script { // Login to DockerHub sh "echo ${DOCKERHUB_CREDENTIALS_PSW} | docker login -u ${DOCKERHUB_CREDENTIALS_USR} --password-stdin" // Push both the specific tag and the latest tag sh "docker push ${IMAGE_NAME}:${IMAGE_TAG}" sh "docker push ${IMAGE_NAME}:latest" } } } } post { always { // Logout from DockerHub and remove images sh "docker logout" sh "docker rmi ${IMAGE_NAME}:${IMAGE_TAG} || true" sh "docker rmi ${IMAGE_NAME}:latest || true" } } }This Jenkins pipeline automates the process of building a Docker image for a Java project, pushing the image to DockerHub, and cleaning up afterward.
Docker Hub

Status

Timings

Build Data

Pipe Overview

Pipe console

Workspace
