Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fa1d1c2
Selenium
imphilippesimo Aug 19, 2021
d6e13ad
Merge branch 'm1ch1' into ready
imphilippesimo Aug 20, 2021
4799acc
Add specific project maven settings
imphilippesimo Aug 20, 2021
c52fc4f
Corect code smells
imphilippesimo Aug 20, 2021
4ff35cb
Configure Jacoco
imphilippesimo Aug 20, 2021
641139b
Coverage ratio set up
imphilippesimo Aug 20, 2021
3508d72
Merge branch 'm1ch2_OK' into ready
imphilippesimo Aug 20, 2021
b6023de
Add profiles configurations
imphilippesimo Aug 25, 2021
1f06bf8
Merge branch 'm1ch3_OK' into ready
imphilippesimo Aug 25, 2021
8bf43ec
Add Jenkinsfile
imphilippesimo Aug 25, 2021
8e32b21
Send email after pipeline
imphilippesimo Aug 26, 2021
4e28d9c
Use your own email please, not mine
Jun 26, 2024
14e3f7d
modification du fichier jenkins
oullemine Dec 9, 2025
33628de
modification du fichier jenkins(master=>main)
oullemine Dec 9, 2025
94213b4
modification du fichier jenkins
oullemine Dec 9, 2025
7185822
modification du fichier pom.xml
oullemine Dec 9, 2025
5282e88
modification du fichier SolutionFormatterTest.java
oullemine Dec 9, 2025
6cb8cae
modification du fichier SolutionFormatterTest.java
oullemine Dec 9, 2025
26ed2ba
modification de l'amil de reciption
oullemine Dec 10, 2025
e965a49
modification de la valeur du waitForQualityGate
oullemine Dec 10, 2025
9e5f32b
modification de la valeur de imageBuild et runApp
oullemine Dec 10, 2025
d07b1b6
modification du fichier Jenkions avec le forcage de l'url sonar
oullemine Dec 12, 2025
a2c88c7
modification du fichier Jenkions avec le forcage de l'url sonar
oullemine Dec 12, 2025
a370045
modification du fichier Jenkions avec le forcage de l'url sonar
oullemine Dec 12, 2025
1d23834
modification du fichier Jenkions avec le forcage de l'url sonar
oullemine Dec 12, 2025
0a7b037
fusionne m2 avec dev
oullemine Dec 12, 2025
40f0f8a
Merge branch 'develop'
oullemine Dec 12, 2025
0945e14
changement du SPRING_PROFILES_ACTIVE
oullemine Dec 12, 2025
eb5bdd3
Merge branch 'develop'
oullemine Dec 12, 2025
67d3b91
changement du SPRING_PROFILES_ACTIVE dans entrypoint.sh
oullemine Dec 15, 2025
af055c6
changement du SPRING_PROFILES_ACTIVE dans entrypoint.sh
oullemine Dec 15, 2025
715764e
changement du titre de l'application
oullemine Dec 15, 2025
3ba8f72
Merge branch 'hotfix-modification-titre' into develop
oullemine Dec 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .m2/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<settings>
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>
http://localhost:9000
</sonar.host.url>
</properties>
</profile>
</profiles>
</settings>
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM adoptopenjdk/openjdk11:alpine-jre

ARG JAR_FILE=target/calculator.jar

WORKDIR /opt/app

COPY ${JAR_FILE} calculator.jar

COPY entrypoint.sh entrypoint.sh

RUN chmod 755 entrypoint.sh

ENTRYPOINT ["./entrypoint.sh"]
146 changes: 146 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
def ENV_NAME = getEnvName(env.BRANCH_NAME)
def CONTAINER_NAME = "calculator-"+ENV_NAME
def CONTAINER_TAG = getTag(env.BUILD_NUMBER, env.BRANCH_NAME)
def HTTP_PORT = getHTTPPort(env.BRANCH_NAME)
def EMAIL_RECIPIENTS = "oullmedacademy1@gmail.com"

node {
try {
stage('Initialize') {
def dockerHome = tool 'DockerLatest'
def mavenHome = tool 'MavenLatest'
env.PATH = "/usr/bin:/bin:${env.PATH}:${mavenHome}/bin"
}

stage('Checkout') {
checkout scm
}

stage('Build with test') {

sh "mvn clean install"
}

stage('Sonarqube Analysis') {
withSonarQubeEnv('SonarQubeLocalServer') {

sh '''
mvn sonar:sonar \
-Dsonar.host.url=http://sonarqube:9000 \
-Dintegration-tests.skip=true \
-Dmaven.test.failure.ignore=true
'''

}
timeout(time: 10, unit: 'MINUTES') {
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}

stage("Image Prune") {
imagePrune(CONTAINER_NAME)
}

stage('Docker sanity') {

sh '''
set -euo pipefail
echo "PATH: $PATH"
echo "which docker: $(which docker || true)"
echo "readlink docker: $(readlink -f $(which docker) || true)"
/usr/bin/docker -v
/usr/bin/docker version
'''

}

stage('Image Build') {
imageBuild(CONTAINER_NAME, CONTAINER_TAG)
}

stage('Push to Docker Registry') {
withCredentials([usernamePassword(credentialsId: 'dockerhubcredentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
pushToImage(CONTAINER_NAME, CONTAINER_TAG, USERNAME, PASSWORD)
}
}

stage('Run App') {
withCredentials([usernamePassword(credentialsId: 'dockerhubcredentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
runApp(CONTAINER_NAME, CONTAINER_TAG, USERNAME, HTTP_PORT, ENV_NAME)

}
}

} finally {
deleteDir()
sendEmail(EMAIL_RECIPIENTS);
}

}

def imagePrune(containerName) {
try {
sh "docker image prune -f"
sh "docker stop $containerName"
} catch (ignored) {
}
}


//def imageBuild(containerName, tag) {
// sh 'docker version' // doit afficher un client et un serveur
// sh "docker build -t $containerName:$tag --pull --no-cache ."
// echo "Image build complete"
//}


def imageBuild(containerName, tag) {
sh '/usr/bin/docker version' // Client 26.x + API 1.45
sh "/usr/bin/docker build -t ${containerName}:${tag} --pull --no-cache ."
echo "Image build complete"
}


def pushToImage(containerName, tag, dockerUser, dockerPassword) {
sh "docker login -u $dockerUser -p $dockerPassword"
sh "docker tag $containerName:$tag $dockerUser/$containerName:$tag"
sh "docker push $dockerUser/$containerName:$tag"
echo "Image push complete"
}

def runApp(containerName, tag, dockerHubUser, httpPort, envName) {
sh "docker pull $dockerHubUser/$containerName:$tag"
sh "docker run --rm --env SPRING_PROFILES_ACTIVE=$envName -d -p $httpPort:$httpPort --name $containerName $dockerHubUser/$containerName:$tag"
echo "Application started on port: ${httpPort} (http)"
}

def sendEmail(recipients) {
mail(
to: recipients,
subject: "Build ${env.BUILD_NUMBER} - ${currentBuild.currentResult} - (${currentBuild.fullDisplayName})",
body: "Check console output at: ${env.BUILD_URL}/console" + "\n")
}

String getEnvName(String branchName) {
if (branchName == 'main') {
return 'prod'
}
return (branchName == 'develop') ? 'uat' : 'dev'
}

String getHTTPPort(String branchName) {
if (branchName == 'main') {
return '9003'
}
return (branchName == 'develop') ? '9002' : '9001'
}

String getTag(String buildNumber, String branchName) {
if (branchName != 'main') {
return buildNumber + '-unstable'
}
return buildNumber + '-stable'
}
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo "The app is starting ..."
exec java -jar -Dspring.profiles.active=${SPRING_PROFILES_ACTIVE} "calculator.jar"
Loading